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.

480 lines
13 KiB

  1. #include "faxcfgwz.h"
  2. #include <shlwapi.h>
  3. PPRINTER_NAMES g_pPrinterNames = NULL;
  4. DWORD g_dwNumPrinters = 0;
  5. BOOL
  6. DirectoryExists(
  7. LPTSTR pDirectoryName
  8. )
  9. /*++
  10. Routine Description:
  11. Check the existancy of given folder name
  12. Arguments:
  13. pDirectoryName - point to folder name
  14. Return Value:
  15. if the folder exists, return TRUE; else, return FALSE.
  16. --*/
  17. {
  18. DWORD dwFileAttributes;
  19. if(!pDirectoryName || lstrlen(pDirectoryName) == 0)
  20. {
  21. return FALSE;
  22. }
  23. dwFileAttributes = GetFileAttributes(pDirectoryName);
  24. if ( dwFileAttributes != 0xffffffff &&
  25. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  26. {
  27. return TRUE;
  28. }
  29. return FALSE;
  30. }
  31. VOID
  32. DoInitRouteOptions(
  33. HWND hDlg
  34. )
  35. /*++
  36. Routine Description:
  37. Initializes the "Route" page with information from system
  38. Arguments:
  39. hDlg - Handle to the "Route" page
  40. Return Value:
  41. NONE
  42. --*/
  43. {
  44. HWND hControl;
  45. DWORD CurrentRM;
  46. DEBUG_FUNCTION_NAME(TEXT("DoInitRouteOptions()"));
  47. hControl = GetDlgItem( hDlg, IDC_RECV_PRINT_TO );
  48. SetLTRComboBox(hDlg, IDC_RECV_PRINT_TO);
  49. //
  50. // Initialize the list of destination printers
  51. //
  52. if (g_pPrinterNames)
  53. {
  54. ReleasePrinterNames (g_pPrinterNames, g_dwNumPrinters);
  55. g_pPrinterNames = NULL;
  56. }
  57. g_pPrinterNames = CollectPrinterNames (&g_dwNumPrinters, TRUE);
  58. if (!g_pPrinterNames)
  59. {
  60. if (ERROR_PRINTER_NOT_FOUND == GetLastError ())
  61. {
  62. //
  63. // No printers
  64. //
  65. }
  66. else
  67. {
  68. //
  69. // Real error
  70. //
  71. }
  72. SendMessage(hControl, CB_SETCURSEL, -1, 0);
  73. SetWindowText(hControl, g_wizData.pRouteInfo[RM_PRINT].tszCurSel);
  74. }
  75. else
  76. {
  77. //
  78. // Success - fill in the combo-box
  79. //
  80. DWORD dw;
  81. LPCWSTR lpcwstrMatchingText;
  82. for (dw = 0; dw < g_dwNumPrinters; dw++)
  83. {
  84. SendMessage(hControl, CB_ADDSTRING, 0, (LPARAM) g_pPrinterNames[dw].lpcwstrDisplayName);
  85. }
  86. //
  87. // Now find out if we match the data the server has
  88. //
  89. if (lstrlen(g_wizData.pRouteInfo[RM_PRINT].tszCurSel))
  90. {
  91. //
  92. // Server has some name for printer
  93. //
  94. lpcwstrMatchingText = FindPrinterNameFromPath (g_pPrinterNames, g_dwNumPrinters, g_wizData.pRouteInfo[RM_PRINT].tszCurSel);
  95. if (!lpcwstrMatchingText)
  96. {
  97. //
  98. // No match, just fill in the text we got from the server
  99. //
  100. SendMessage(hControl, CB_SETCURSEL, -1, 0);
  101. SetWindowText(hControl, g_wizData.pRouteInfo[RM_PRINT].tszCurSel);
  102. }
  103. else
  104. {
  105. SendMessage(hControl, CB_SELECTSTRING, -1, (LPARAM) lpcwstrMatchingText);
  106. }
  107. }
  108. else
  109. {
  110. //
  111. // No server configuation - display no selection
  112. //
  113. }
  114. }
  115. //
  116. // Display routing methods info in the dialog.
  117. //
  118. for (CurrentRM = 0; CurrentRM < RM_COUNT; CurrentRM++)
  119. {
  120. BOOL bEnabled;
  121. LPTSTR tszCurSel;
  122. //
  123. // if we don't have this kind of method, go to the next one
  124. //
  125. tszCurSel = g_wizData.pRouteInfo[CurrentRM].tszCurSel;
  126. bEnabled = g_wizData.pRouteInfo[CurrentRM].bEnabled;
  127. switch (CurrentRM)
  128. {
  129. case RM_FOLDER:
  130. CheckDlgButton( hDlg, IDC_RECV_SAVE, bEnabled ? BST_CHECKED : BST_UNCHECKED );
  131. EnableWindow( GetDlgItem( hDlg, IDC_RECV_DEST_FOLDER ), bEnabled );
  132. EnableWindow( GetDlgItem( hDlg, IDC_RECV_BROWSE_DIR ), bEnabled );
  133. if (*tszCurSel)
  134. {
  135. SetDlgItemText( hDlg, IDC_RECV_DEST_FOLDER, tszCurSel );
  136. }
  137. break;
  138. case RM_PRINT:
  139. CheckDlgButton( hDlg, IDC_RECV_PRINT, bEnabled ? BST_CHECKED : BST_UNCHECKED );
  140. EnableWindow(GetDlgItem(hDlg, IDC_RECV_PRINT_TO), bEnabled);
  141. break;
  142. }
  143. }
  144. }
  145. BOOL
  146. DoSaveRouteOptions(
  147. HWND hDlg
  148. )
  149. /*++
  150. Routine Description:
  151. Save the information on the "Route" page to system
  152. Arguments:
  153. hDlg - Handle to the "Route" page
  154. Return Value:
  155. TRUE if success, else FALSE
  156. --*/
  157. {
  158. HWND hControl;
  159. DWORD i;
  160. ROUTINFO SetInfo[RM_COUNT] = {0};
  161. LPTSTR lpCurSel;
  162. BOOL* pbEnabled;
  163. DEBUG_FUNCTION_NAME(TEXT("DoSaveRouteOptions()"));
  164. //
  165. // Check the validity first in the loop,
  166. // then save the routing info
  167. //
  168. for (i = 0; i < RM_COUNT; i++)
  169. {
  170. lpCurSel = SetInfo[i].tszCurSel;
  171. Assert(lpCurSel);
  172. pbEnabled = &(SetInfo[i].bEnabled);
  173. Assert(pbEnabled);
  174. *pbEnabled = 0;
  175. switch (i)
  176. {
  177. case RM_PRINT:
  178. *pbEnabled = (IsDlgButtonChecked( hDlg, IDC_RECV_PRINT ) == BST_CHECKED);
  179. if(FALSE == *pbEnabled)
  180. {
  181. break;
  182. }
  183. hControl = GetDlgItem(hDlg, IDC_RECV_PRINT_TO);
  184. lpCurSel[0] = TEXT('\0');
  185. //
  186. // Just read-in the selected printer display name
  187. //
  188. GetDlgItemText (hDlg, IDC_RECV_PRINT_TO, lpCurSel, MAX_PATH);
  189. //
  190. // we will check the validity only when this routing method is enabled
  191. // but we will save the select change anyway.
  192. //
  193. if (*pbEnabled)
  194. {
  195. if (lpCurSel[0] == 0)
  196. {
  197. DisplayMessageDialog( hDlg, 0, 0, IDS_ERR_SELECT_PRINTER );
  198. SetFocus(hControl);
  199. SetActiveWindow(hControl);
  200. goto error;
  201. }
  202. }
  203. break;
  204. case RM_FOLDER:
  205. {
  206. BOOL bValid = TRUE;
  207. HCURSOR hOldCursor;
  208. hControl = GetDlgItem(hDlg, IDC_RECV_DEST_FOLDER);
  209. *pbEnabled = (IsDlgButtonChecked( hDlg, IDC_RECV_SAVE ) == BST_CHECKED);
  210. if(!*pbEnabled)
  211. {
  212. break;
  213. }
  214. GetWindowText( hControl, lpCurSel, MAX_PATH - 1 );
  215. //
  216. // Validate the directory
  217. //
  218. hOldCursor = SetCursor (LoadCursor(NULL, IDC_WAIT));
  219. if(!FaxCheckValidFaxFolder(g_hFaxSvcHandle, lpCurSel))
  220. {
  221. DWORD dwRes = GetLastError();
  222. DebugPrintEx(DEBUG_ERR, TEXT("FaxCheckValidFaxFolder failed (ec: %ld)"), dwRes);
  223. //
  224. // Try to adjust folder
  225. //
  226. dwRes = AskUserAndAdjustFaxFolder(hDlg, NULL, lpCurSel, dwRes);
  227. if(ERROR_SUCCESS != dwRes)
  228. {
  229. bValid = FALSE;
  230. if(ERROR_BAD_PATHNAME != dwRes)
  231. {
  232. //
  233. // The error message has not been shown by AskUserAndAdjustFaxFolder
  234. //
  235. DisplayMessageDialog( hDlg, 0, 0, IDS_ERR_ARCHIVE_DIR );
  236. }
  237. }
  238. }
  239. SetCursor (hOldCursor);
  240. if(!bValid)
  241. {
  242. // go to the "Browse" button
  243. hControl = GetDlgItem(hDlg, IDC_RECV_BROWSE_DIR);
  244. SetFocus(hControl);
  245. SetActiveWindow(hControl);
  246. goto error;
  247. }
  248. }
  249. }
  250. }
  251. //
  252. // now save the device and routing info into shared data.
  253. //
  254. CopyMemory((LPVOID)(g_wizData.pRouteInfo), (LPVOID)SetInfo, RM_COUNT * sizeof(ROUTINFO));
  255. return TRUE;
  256. error:
  257. return FALSE;
  258. }
  259. INT_PTR
  260. CALLBACK
  261. RecvRouteDlgProc (
  262. HWND hDlg,
  263. UINT uMsg,
  264. WPARAM wParam,
  265. LPARAM lParam
  266. )
  267. /*++
  268. Routine Description:
  269. Procedure for handling the "Route" page
  270. Arguments:
  271. hDlg - Identifies the property sheet page
  272. uMsg - Specifies the message
  273. wParam - Specifies additional message-specific information
  274. lParam - Specifies additional message-specific information
  275. Return Value:
  276. Depends on the value of message parameter
  277. --*/
  278. #define EnableRouteWindow( id, idResource ) \
  279. EnableWindow( GetDlgItem(hDlg, idResource), IsDlgButtonChecked(hDlg, id) )
  280. {
  281. switch (uMsg)
  282. {
  283. case WM_INITDIALOG :
  284. {
  285. //
  286. // Maximum length for various text fields in the dialog
  287. //
  288. static INT textLimits[] =
  289. {
  290. IDC_RECV_DEST_FOLDER, MAX_PATH,
  291. 0,
  292. };
  293. LimitTextFields(hDlg, textLimits);
  294. DoInitRouteOptions(hDlg);
  295. SetLTREditDirection(hDlg, IDC_RECV_DEST_FOLDER);
  296. SHAutoComplete (GetDlgItem(hDlg, IDC_RECV_DEST_FOLDER), SHACF_FILESYSTEM);
  297. return TRUE;
  298. }
  299. case WM_COMMAND:
  300. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  301. {
  302. case BN_CLICKED:
  303. switch(GET_WM_COMMAND_ID(wParam, lParam))
  304. {
  305. case IDC_RECV_PRINT:
  306. EnableRouteWindow(IDC_RECV_PRINT, IDC_RECV_PRINT_TO);
  307. break;
  308. case IDC_RECV_SAVE:
  309. EnableRouteWindow(IDC_RECV_SAVE, IDC_RECV_DEST_FOLDER);
  310. EnableRouteWindow(IDC_RECV_SAVE, IDC_RECV_BROWSE_DIR);
  311. break;
  312. case IDC_RECV_BROWSE_DIR:
  313. {
  314. TCHAR szTitle[MAX_PATH] = {0};
  315. if( !LoadString( g_hResource, IDS_RECV_BROWSE_DIR, szTitle, MAX_PATH ) )
  316. {
  317. DEBUG_FUNCTION_NAME(TEXT("RecvRouteDlgProc()"));
  318. DebugPrintEx(DEBUG_ERR,
  319. TEXT("LoadString failed: string ID=%d, error=%d"),
  320. IDS_RECV_BROWSE_DIR,
  321. GetLastError());
  322. }
  323. if( !BrowseForDirectory(hDlg, IDC_RECV_DEST_FOLDER, szTitle) )
  324. {
  325. return FALSE;
  326. }
  327. break;
  328. }
  329. }
  330. break;
  331. default:
  332. break;
  333. }
  334. break;
  335. case WM_NOTIFY :
  336. {
  337. LPNMHDR lpnm = (LPNMHDR) lParam;
  338. switch (lpnm->code)
  339. {
  340. case PSN_SETACTIVE : //Enable the Back and Finish button
  341. //
  342. // Check the "Next" button status
  343. //
  344. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  345. break;
  346. case PSN_WIZBACK :
  347. {
  348. //
  349. // Handle a Back button click here
  350. //
  351. if(RemoveLastPage(hDlg))
  352. {
  353. return TRUE;
  354. }
  355. break;
  356. }
  357. case PSN_WIZNEXT :
  358. //Handle a Next button click, if necessary
  359. if(!DoSaveRouteOptions(hDlg))
  360. {
  361. //
  362. // not finished with route configuration
  363. //
  364. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, -1);
  365. return TRUE;
  366. }
  367. SetLastPage(IDD_WIZARD_RECV_ROUTE);
  368. break;
  369. case PSN_RESET :
  370. {
  371. // Handle a Cancel button click, if necessary
  372. break;
  373. }
  374. default :
  375. break;
  376. }
  377. }
  378. break;
  379. default:
  380. break;
  381. }
  382. return FALSE;
  383. }