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.

572 lines
18 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. config.cpp
  5. Abstract:
  6. This module contains routines for the fax config dialog.
  7. Author:
  8. Wesley Witt (wesw) 13-Aug-1996
  9. --*/
  10. #include "faxext.h"
  11. #include "faxhelp.h"
  12. #include "resource.h"
  13. extern HINSTANCE hInstance;
  14. VOID
  15. AddCoverPagesToList(
  16. HWND hwndList,
  17. LPSTR pDirPath,
  18. BOOL ServerCoverPage
  19. )
  20. /*++
  21. Routine Description:
  22. Add the cover page files in the specified directory to a listbox
  23. Arguments:
  24. hwndList - Handle to a list window
  25. pDirPath - Directory to look for coverpage files
  26. ServerCoverPage - TRUE if the dir contains server cover pages
  27. Return Value:
  28. NONE
  29. --*/
  30. {
  31. WIN32_FIND_DATA findData;
  32. CHAR filename[MAX_PATH];
  33. CHAR CpName[MAX_PATH];
  34. HANDLE hFindFile;
  35. LPSTR pFilename;
  36. LPSTR pExtension;
  37. INT listIndex;
  38. INT dirLen;
  39. INT fileLen;
  40. INT flags = CPFLAG_LINK;
  41. INT Cnt = 2;
  42. //
  43. // Copy the directory path to a local buffer
  44. //
  45. if (pDirPath == NULL || pDirPath[0] == 0) {
  46. return;
  47. }
  48. if ((dirLen = strlen( pDirPath )) >= MAX_PATH - MAX_FILENAME_EXT - 1) {
  49. return;
  50. }
  51. strcpy( filename, pDirPath );
  52. if (filename[dirLen] != '\\') {
  53. filename[dirLen] = '\\';
  54. filename[dirLen+1] = '\0';
  55. dirLen++;
  56. }
  57. //
  58. // Go through the following loop twice:
  59. // Once to add the files with .ncp extension
  60. // Again to add the files with .lnk extension
  61. //
  62. // Don't chase links for server based cover pages
  63. //
  64. while( Cnt ) {
  65. //
  66. // Generate a specification for the files we're interested in
  67. //
  68. pFilename = &filename[dirLen];
  69. *pFilename = TEXT('*');
  70. strcpy( pFilename+1, ServerCoverPage ? CP_FILENAME_EXT : (flags & CPFLAG_LINK) ? LNK_FILENAME_EXT : CP_FILENAME_EXT );
  71. //
  72. // Call FindFirstFile/FindNextFile to enumerate the files
  73. // matching our specification
  74. //
  75. hFindFile = FindFirstFile( filename, &findData );
  76. if (hFindFile != INVALID_HANDLE_VALUE) {
  77. do {
  78. //
  79. // Exclude directories and hidden files
  80. //
  81. if (findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_DIRECTORY)) {
  82. continue;
  83. }
  84. //
  85. // Make sure we have enough room to store the full pathname
  86. //
  87. if ((fileLen = strlen( findData.cFileName)) <= MAX_FILENAME_EXT ) {
  88. continue;
  89. }
  90. if (fileLen + dirLen >= MAX_PATH) {
  91. continue;
  92. }
  93. //
  94. // If we're chasing links, make sure the link refers to
  95. // a cover page file.
  96. //
  97. if (!ServerCoverPage && (flags & CPFLAG_LINK)) {
  98. strcpy( pFilename, findData.cFileName );
  99. if (!IsCoverPageShortcut(filename)) {
  100. continue;
  101. }
  102. }
  103. //
  104. // Don't display the filename extension
  105. //
  106. if (pExtension = strrchr(findData.cFileName,'.')) {
  107. *pExtension = NULL;
  108. }
  109. //
  110. // Add the cover page name to the list window
  111. //
  112. strcpy( CpName, findData.cFileName );
  113. if ( ! ServerCoverPage )
  114. {
  115. char szPersonal[30];
  116. LoadString( hInstance, IDS_PERSONAL, szPersonal, 30 );
  117. strcat( CpName, (char *) " " );
  118. strcat( CpName, szPersonal );
  119. }
  120. listIndex = (INT)SendMessage(
  121. hwndList,
  122. LB_ADDSTRING,
  123. 0,
  124. (LPARAM) CpName
  125. );
  126. if (listIndex != LB_ERR) {
  127. SendMessage( hwndList, LB_SETITEMDATA, listIndex, ServerCoverPage );
  128. }
  129. } while (FindNextFile(hFindFile, &findData));
  130. FindClose(hFindFile);
  131. }
  132. flags ^= CPFLAG_LINK;
  133. Cnt -= 1;
  134. if (ServerCoverPage) {
  135. Cnt -= 1;
  136. }
  137. }
  138. }
  139. LONG
  140. MyLineGetTransCaps(
  141. LPLINETRANSLATECAPS *LineTransCaps
  142. )
  143. {
  144. DWORD LineTransCapsSize;
  145. LONG Rslt = ERROR_SUCCESS;
  146. //
  147. // allocate the initial linetranscaps structure
  148. //
  149. LineTransCapsSize = sizeof(LINETRANSLATECAPS) + 4096;
  150. *LineTransCaps = (LPLINETRANSLATECAPS) MemAlloc( LineTransCapsSize );
  151. if (!*LineTransCaps) {
  152. Rslt = ERROR_NOT_ENOUGH_MEMORY;
  153. goto exit;
  154. }
  155. (*LineTransCaps)->dwTotalSize = LineTransCapsSize;
  156. Rslt = lineGetTranslateCaps(
  157. NULL,
  158. 0x00020000,
  159. *LineTransCaps
  160. );
  161. if (Rslt != 0) {
  162. goto exit;
  163. }
  164. if ((*LineTransCaps)->dwNeededSize > (*LineTransCaps)->dwTotalSize) {
  165. //
  166. // re-allocate the LineTransCaps structure
  167. //
  168. LineTransCapsSize = (*LineTransCaps)->dwNeededSize;
  169. MemFree( *LineTransCaps );
  170. *LineTransCaps = (LPLINETRANSLATECAPS) MemAlloc( LineTransCapsSize );
  171. if (!*LineTransCaps) {
  172. Rslt = ERROR_NOT_ENOUGH_MEMORY;
  173. goto exit;
  174. }
  175. (*LineTransCaps)->dwTotalSize = LineTransCapsSize;
  176. Rslt = lineGetTranslateCaps(
  177. NULL,
  178. 0x00020000,
  179. *LineTransCaps
  180. );
  181. if (Rslt != 0) {
  182. goto exit;
  183. }
  184. }
  185. exit:
  186. if (Rslt != ERROR_SUCCESS) {
  187. MemFree( *LineTransCaps );
  188. *LineTransCaps = NULL;
  189. }
  190. return Rslt;
  191. }
  192. INT_PTR CALLBACK
  193. ConfigDlgProc(
  194. HWND hDlg,
  195. UINT message,
  196. WPARAM wParam,
  197. LPARAM lParam
  198. )
  199. /*++
  200. Routine Description:
  201. Dialog procedure for the fax mail transport configuration
  202. Arguments:
  203. hDlg - Window handle for this dialog
  204. message - Message number
  205. wParam - Parameter #1
  206. lParam - Parameter #2
  207. Return Value:
  208. TRUE - Message was handled
  209. FALSE - Message was NOT handled
  210. --*/
  211. {
  212. static LPLINETRANSLATECAPS LineTransCaps = NULL;
  213. static LPLINELOCATIONENTRY LineLocation = NULL;
  214. static PFAXXP_CONFIG FaxConfig;
  215. static HWND hwndListPrn;
  216. static HWND hwndListCov;
  217. static HWND hwndListLoc;
  218. static BOOL LocalPrinter;
  219. static const DWORD faxextHelpIDs[] = {
  220. IDC_PRINTER_LIST, IDH_FMA_FAX_PRINTERS,
  221. IDC_USE_COVERPAGE, IDH_FMA_INCLUDE_COVER_PAGE,
  222. IDC_COVERPAGE_LIST, IDH_FMA_COVER_PAGES,
  223. IDC_DIALING_LOCATION, IDH_FMA_DIALING_LOCATION,
  224. IDC_STATIC_DIALING_LOCATION,IDH_FMA_DIALING_LOCATION,
  225. IDC_STATIC_COVERPAGE_GRP, IDH_FMA_COVER_PAGES,
  226. IDC_STATIC_COVERPAGE, IDH_FMA_COVER_PAGES,
  227. IDC_STATIC_PRINTER_LIST, IDH_FMA_FAX_PRINTERS,
  228. IDC_STATIC, (ULONG)IDH_INACTIVE,
  229. 0, 0
  230. };
  231. PPRINTER_INFO_2 PrinterInfo;
  232. DWORD CountPrinters;
  233. DWORD Selection = 0;
  234. BOOL Match;
  235. CHAR Buffer[256];
  236. CHAR CpDir[MAX_PATH];
  237. LPSTR p;
  238. DWORD i;
  239. DWORD_PTR j;
  240. HANDLE hFax;
  241. PFAX_CONFIGURATION pFaxConfiguration;
  242. DWORD dwPermanentLocationID = 0;
  243. LPSTR pLocationName = NULL;
  244. switch( message ) {
  245. case WM_INITDIALOG:
  246. FaxConfig = (PFAXXP_CONFIG) lParam;
  247. //
  248. // defer the server CP check to this point so we don't fire up fax service
  249. // unless we really need this property
  250. //
  251. if (FaxConnectFaxServer(FaxConfig->ServerName,&hFax) ){
  252. if (FaxGetConfiguration(hFax,&pFaxConfiguration) ){
  253. FaxConfig->ServerCpOnly = pFaxConfiguration->ServerCp;
  254. FaxFreeBuffer(pFaxConfiguration);
  255. }
  256. FaxClose(hFax);
  257. }
  258. hwndListPrn = GetDlgItem( hDlg, IDC_PRINTER_LIST );
  259. hwndListCov = GetDlgItem( hDlg, IDC_COVERPAGE_LIST );
  260. hwndListLoc = GetDlgItem( hDlg, IDC_DIALING_LOCATION );
  261. Buffer[0] = 0;
  262. PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &CountPrinters, PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS );
  263. Match = FALSE;
  264. if (PrinterInfo) {
  265. for (i=0,j=0; i<CountPrinters; i++) {
  266. if (strcmp( PrinterInfo[i].pDriverName, FAX_DRIVER_NAME ) == 0) {
  267. SendMessage( hwndListPrn, CB_ADDSTRING, 0, (LPARAM) PrinterInfo[i].pPrinterName );
  268. if (FaxConfig->PrinterName && strcmp( PrinterInfo[i].pPrinterName, FaxConfig->PrinterName ) == 0) {
  269. Match = TRUE;
  270. if (PrinterInfo[i].pServerName) {
  271. strcpy( Buffer, PrinterInfo[i].pServerName );
  272. }
  273. }
  274. j += 1;
  275. }
  276. }
  277. if (j == 0) {
  278. //
  279. // no fax printers
  280. //
  281. goto cp;
  282. }
  283. if (!Match) {
  284. MemFree( FaxConfig->PrinterName );
  285. FaxConfig->PrinterName = StringDup( PrinterInfo[0].pPrinterName );
  286. }
  287. MemFree( PrinterInfo );
  288. SendMessage( hwndListPrn, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) FaxConfig->PrinterName );
  289. PrinterInfo = (PPRINTER_INFO_2) MyGetPrinter( FaxConfig->PrinterName, 2 );
  290. if (PrinterInfo && (PrinterInfo->Attributes & PRINTER_ATTRIBUTE_LOCAL)) {
  291. LocalPrinter = TRUE;
  292. } else {
  293. LocalPrinter = FALSE;
  294. }
  295. MemFree( PrinterInfo );
  296. }
  297. cp:
  298. if (FaxConfig->UseCoverPage) {
  299. CheckDlgButton( hDlg, IDC_USE_COVERPAGE, BST_CHECKED );
  300. } else {
  301. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), FALSE );
  302. }
  303. GetServerCpDir( Buffer[0] ? Buffer : NULL, CpDir, sizeof(CpDir) );
  304. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  305. if (!FaxConfig->ServerCpOnly) {
  306. GetClientCpDir( CpDir, sizeof(CpDir) );
  307. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  308. }
  309. Selection = (DWORD)SendMessage( hwndListCov, LB_FINDSTRING, 0, (LPARAM) FaxConfig->CoverPageName );
  310. if (Selection == LB_ERR) {
  311. Selection = 0;
  312. }
  313. SendMessage( hwndListCov, LB_SETCURSEL, (WPARAM) Selection, 0 );
  314. MyLineGetTransCaps( &LineTransCaps );
  315. if (LineTransCaps && LineTransCaps->dwLocationListSize && LineTransCaps->dwLocationListOffset) {
  316. LineLocation = (LPLINELOCATIONENTRY) ((LPBYTE)LineTransCaps + LineTransCaps->dwLocationListOffset);
  317. for (i=0; i<LineTransCaps->dwNumLocations; i++) {
  318. if (LineLocation[i].dwLocationNameSize && LineLocation[i].dwLocationNameOffset) {
  319. j = SendMessage(
  320. hwndListLoc,
  321. CB_ADDSTRING,
  322. 0,
  323. (LPARAM) (LPSTR) ((LPBYTE)LineTransCaps + LineLocation[i].dwLocationNameOffset)
  324. );
  325. SendMessage(
  326. hwndListLoc,
  327. CB_SETITEMDATA,
  328. j,
  329. (LPARAM) LineLocation[i].dwPermanentLocationID
  330. );
  331. if (LineLocation[i].dwPermanentLocationID == LineTransCaps->dwCurrentLocationID) {
  332. pLocationName = (LPSTR) ((LPBYTE)LineTransCaps + LineLocation[i].dwLocationNameOffset);
  333. }
  334. }
  335. }
  336. if (pLocationName) {
  337. SendMessage( hwndListLoc, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) pLocationName );
  338. }
  339. }
  340. if (!LocalPrinter) {
  341. EnableWindow( hwndListLoc, FALSE );
  342. }
  343. break;
  344. case WM_COMMAND:
  345. if (HIWORD(wParam) == BN_CLICKED) {
  346. if (LOWORD(wParam) == IDC_USE_COVERPAGE) {
  347. if (IsDlgButtonChecked( hDlg, IDC_USE_COVERPAGE ) == BST_CHECKED) {
  348. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), TRUE );
  349. } else {
  350. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), FALSE );
  351. }
  352. return FALSE;
  353. }
  354. }
  355. if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_PRINTER_LIST) {
  356. Selection = (DWORD)SendMessage( hwndListPrn, CB_GETCURSEL, 0, 0 );
  357. SendMessage( hwndListPrn, CB_GETLBTEXT, Selection, (LPARAM) Buffer );
  358. PrinterInfo = (PPRINTER_INFO_2) MyGetPrinter( Buffer, 2 );
  359. if (PrinterInfo && (PrinterInfo->Attributes & PRINTER_ATTRIBUTE_LOCAL)) {
  360. LocalPrinter = TRUE;
  361. } else {
  362. LocalPrinter = FALSE;
  363. }
  364. EnableWindow( hwndListLoc, LocalPrinter );
  365. SendMessage( hwndListCov, LB_RESETCONTENT, 0, 0 );
  366. GetServerCpDir( PrinterInfo ? PrinterInfo->pServerName : NULL, CpDir, sizeof(CpDir) );
  367. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  368. //
  369. // check if the server name has changed
  370. // (so we can update the "server CP only" flag)
  371. //
  372. BOOL ServerNameChange = FALSE;
  373. if (FaxConfig->ServerName) {
  374. if (PrinterInfo && PrinterInfo->pServerName) {
  375. if (strcmp(FaxConfig->ServerName,PrinterInfo->pServerName) != 0) {
  376. MemFree(FaxConfig->ServerName);
  377. FaxConfig->ServerName = StringDup(PrinterInfo->pServerName);
  378. ServerNameChange = TRUE;
  379. }
  380. } else {
  381. MemFree(FaxConfig->ServerName);
  382. FaxConfig->ServerName = NULL;
  383. ServerNameChange = TRUE;
  384. }
  385. } else if (PrinterInfo && PrinterInfo->pServerName) {
  386. FaxConfig->ServerName = StringDup(PrinterInfo->pServerName);
  387. ServerNameChange = TRUE;
  388. }
  389. if (ServerNameChange) {
  390. HANDLE hFax;
  391. PFAX_CONFIGURATION pFaxConfiguration;
  392. FaxConfig->ServerCpOnly = FALSE;
  393. if (FaxConnectFaxServer(FaxConfig->ServerName,&hFax) ){
  394. if (FaxGetConfiguration(hFax,&pFaxConfiguration) ){
  395. FaxConfig->ServerCpOnly = pFaxConfiguration->ServerCp;
  396. FaxFreeBuffer(pFaxConfiguration);
  397. }
  398. FaxClose(hFax);
  399. }
  400. }
  401. if (! FaxConfig->ServerCpOnly) {
  402. GetClientCpDir( CpDir, sizeof(CpDir) );
  403. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  404. }
  405. SendMessage( hwndListCov, LB_SETCURSEL, 0, 0 );
  406. MemFree( PrinterInfo );
  407. }
  408. switch (wParam) {
  409. case IDOK :
  410. FaxConfig->UseCoverPage = IsDlgButtonChecked( hDlg, IDC_USE_COVERPAGE ) == BST_CHECKED;
  411. Selection = (DWORD)SendMessage( hwndListPrn, CB_GETCURSEL, 0, 0 );
  412. SendMessage( hwndListPrn, CB_GETLBTEXT, Selection, (LPARAM) Buffer );
  413. MemFree( FaxConfig->PrinterName );
  414. FaxConfig->PrinterName = StringDup( Buffer );
  415. Selection = (DWORD)SendMessage( hwndListCov, LB_GETCURSEL, 0, 0 );
  416. SendMessage( hwndListCov, LB_GETTEXT, Selection, (LPARAM) Buffer );
  417. MemFree( FaxConfig->CoverPageName );
  418. // Local cover page files are presented with the string " (Personal)"
  419. // appended to the base of the cover page file name. Note the presence
  420. // of a space character. The following code segment removes that string
  421. // if it is present, before setting the CoverPageName member of FaxConfig.
  422. p = strstr( Buffer, (const char *) " (" );
  423. if ( p != NULL )
  424. {
  425. *p = (CHAR) '\0';
  426. }
  427. FaxConfig->CoverPageName = StringDup( Buffer );
  428. FaxConfig->ServerCoverPage = (INT)SendMessage( hwndListCov, LB_GETITEMDATA, Selection, 0 );
  429. Selection = (DWORD)SendMessage( hwndListLoc, CB_GETCURSEL, 0, 0 );
  430. if (Selection >= 0 && LineTransCaps) {
  431. dwPermanentLocationID = (DWORD) SendMessage( hwndListLoc, CB_GETITEMDATA, Selection, 0);
  432. if (dwPermanentLocationID != LineTransCaps->dwCurrentLocationID) {
  433. lineSetCurrentLocation( NULL, dwPermanentLocationID );
  434. }
  435. }
  436. if (LineTransCaps) {
  437. MemFree( LineTransCaps );
  438. }
  439. EndDialog( hDlg, IDOK );
  440. break;
  441. case IDCANCEL:
  442. MemFree( LineTransCaps );
  443. EndDialog( hDlg, IDCANCEL );
  444. break;
  445. }
  446. break;
  447. case WM_HELP:
  448. case WM_CONTEXTMENU:
  449. FAXWINHELP( message, wParam, lParam, faxextHelpIDs );
  450. break;
  451. }
  452. return FALSE;
  453. }