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.

585 lines
19 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 "faxxp.h"
  11. #include "faxhelp.h"
  12. #include "resource.h"
  13. #pragma hdrstop
  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( FaxXphInstance, 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. VOID
  140. DrawSampleText(
  141. HWND hDlg,
  142. HDC hDC,
  143. PFAXXP_CONFIG FaxConfig
  144. )
  145. {
  146. int PointSize;
  147. TCHAR PointSizeBuffer[16];
  148. TCHAR FontTypeBuffer[32];
  149. BOOL bItalic = FALSE;
  150. BOOL bBold = FALSE;
  151. PointSize = abs ( MulDiv((int) FaxConfig->FontStruct.lfHeight, 72, GetDeviceCaps( hDC, LOGPIXELSY)));
  152. _stprintf( PointSizeBuffer, TEXT("%d"), PointSize );
  153. SetWindowText( GetDlgItem( hDlg, IDC_FONT_SIZE ), PointSizeBuffer );
  154. SetWindowText( GetDlgItem( hDlg, IDC_FONT_NAME), FaxConfig->FontStruct.lfFaceName );
  155. //
  156. // get the font type
  157. //
  158. ZeroMemory(FontTypeBuffer, sizeof(FontTypeBuffer) );
  159. if (FaxConfig->FontStruct.lfItalic) {
  160. bItalic = TRUE;
  161. }
  162. if ( FaxConfig->FontStruct.lfWeight == FW_BOLD ) {
  163. bBold = TRUE;
  164. }
  165. if (bBold) {
  166. LoadString(FaxXphInstance, IDS_FONT_BOLD, FontTypeBuffer,sizeof(FontTypeBuffer)/sizeof(TCHAR) );
  167. // concat "italic"
  168. if (bItalic) {
  169. LoadString(FaxXphInstance,
  170. IDS_FONT_ITALIC,
  171. &FontTypeBuffer[lstrlen(FontTypeBuffer)],
  172. sizeof(FontTypeBuffer)/sizeof(TCHAR) - lstrlen(FontTypeBuffer) );
  173. }
  174. } else if (bItalic) {
  175. LoadString(FaxXphInstance, IDS_FONT_ITALIC, FontTypeBuffer,sizeof(FontTypeBuffer)/sizeof(TCHAR) );
  176. } else {
  177. LoadString(FaxXphInstance, IDS_FONT_REGULAR, FontTypeBuffer,sizeof(FontTypeBuffer)/sizeof(TCHAR) );
  178. }
  179. SetWindowText( GetDlgItem( hDlg, IDC_FONT_STYLE), FontTypeBuffer );
  180. }
  181. INT_PTR CALLBACK
  182. ConfigDlgProc(
  183. HWND hDlg,
  184. UINT message,
  185. WPARAM wParam,
  186. LPARAM lParam
  187. )
  188. /*++
  189. Routine Description:
  190. Dialog procedure for the fax mail transport configuration
  191. Arguments:
  192. hDlg - Window handle for this dialog
  193. message - Message number
  194. wParam - Parameter #1
  195. lParam - Parameter #2
  196. Return Value:
  197. TRUE - Message was handled
  198. FALSE - Message was NOT handled
  199. --*/
  200. {
  201. static PFAXXP_CONFIG FaxConfig;
  202. static HWND hwndListPrn;
  203. static HWND hwndListCov;
  204. static const DWORD faxextHelpIDs[] = {
  205. IDC_PRINTER_LIST, IDH_FAXMAILTRANSPORT_FAX_PRINTERS,
  206. IDC_STATIC_PRINTERS, IDH_FAXMAILTRANSPORT_FAX_PRINTERS,
  207. IDC_USE_COVERPAGE, IDH_FAXMAILTRANSPORT_INCLUDE_COVER_PAGE,
  208. IDC_COVERPAGE_LIST, IDH_FAXMAILTRANSPORT_COVER_PAGES,
  209. IDC_COVERPAGE_LIST_LABEL, IDH_FAXMAILTRANSPORT_COVER_PAGES,
  210. IDCSTATIC_FONT_GROUP, IDH_FAXMAILTRANSPORT_DEFAULT_MESSAGE_FONT_GRP,
  211. IDCSTATIC_FONT, IDH_FAXMAILTRANSPORT_FONT,
  212. IDCSTATIC_FONTSTYLE, IDH_FAXMAILTRANSPORT_FONT_STYLE,
  213. IDCSTATIC_FONTSIZE, IDH_FAXMAILTRANSPORT_SIZE,
  214. IDC_FONT_NAME, IDH_FAXMAILTRANSPORT_FONT,
  215. IDC_FONT_STYLE, IDH_FAXMAILTRANSPORT_FONT_STYLE,
  216. IDC_FONT_SIZE, IDH_FAXMAILTRANSPORT_SIZE,
  217. IDC_SET_FONT, IDH_FAXMAILTRANSPORT_SET_FONT,
  218. IDC_STATIC, (LONG)IDH_INACTIVE,
  219. IDC_STATIC_ICON, (LONG)IDH_INACTIVE,
  220. IDC_STATIC_TITLE, (LONG)IDH_INACTIVE,
  221. 0, 0
  222. };
  223. PPRINTER_INFO_2 PrinterInfo;
  224. DWORD CountPrinters;
  225. DWORD Selection = 0;
  226. CHAR Buffer[256];
  227. CHAR CpDir[MAX_PATH];
  228. LPSTR p;
  229. PAINTSTRUCT ps;
  230. #ifndef WIN95
  231. HANDLE hFax;
  232. PFAX_CONFIGURATION pFaxConfiguration;
  233. #endif
  234. switch( message ) {
  235. case WM_INITDIALOG:
  236. FaxConfig = (PFAXXP_CONFIG) lParam;
  237. #ifndef WIN95
  238. //
  239. // defer the server CP check to this point so we don't fire up fax service
  240. // unless we really need this property
  241. //
  242. if (FaxConnectFaxServer(FaxConfig->ServerName,&hFax) ){
  243. if (FaxGetConfiguration(hFax,&pFaxConfiguration) ){
  244. FaxConfig->ServerCpOnly = pFaxConfiguration->ServerCp;
  245. FaxFreeBuffer(pFaxConfiguration);
  246. }
  247. FaxClose(hFax);
  248. }
  249. #endif
  250. hwndListPrn = GetDlgItem( hDlg, IDC_PRINTER_LIST );
  251. hwndListCov = GetDlgItem( hDlg, IDC_COVERPAGE_LIST );
  252. //
  253. // populate the printers listbox
  254. //
  255. Buffer[0] = 0;
  256. PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &CountPrinters, PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS );
  257. if (PrinterInfo) {
  258. DWORD i,j;
  259. for (i=0,j=0; i<CountPrinters; i++) {
  260. if (strcmp( PrinterInfo[i].pDriverName, FAX_DRIVER_NAME ) == 0) {
  261. SendMessage( hwndListPrn, CB_ADDSTRING, 0, (LPARAM) PrinterInfo[i].pPrinterName );
  262. if (FaxConfig->PrinterName && strcmp( PrinterInfo[i].pPrinterName, FaxConfig->PrinterName ) == 0) {
  263. #if defined(WIN95)
  264. if (PrinterInfo[i].pPortName) {
  265. strcpy( Buffer, PrinterInfo[i].pPortName );
  266. }
  267. #else
  268. if (PrinterInfo[i].pServerName) {
  269. strcpy( Buffer, PrinterInfo[i].pServerName );
  270. }
  271. #endif
  272. }
  273. j += 1;
  274. }
  275. }
  276. MemFree( PrinterInfo );
  277. SendMessage( hwndListPrn, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) FaxConfig->PrinterName );
  278. }
  279. if (FaxConfig->UseCoverPage) {
  280. CheckDlgButton( hDlg, IDC_USE_COVERPAGE, BST_CHECKED );
  281. } else {
  282. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), FALSE );
  283. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST_LABEL ), FALSE );
  284. }
  285. #if defined(WIN95)
  286. if (Buffer[0]) {
  287. char *LastWhack;
  288. LastWhack = strrchr(Buffer, '\\');
  289. if (LastWhack != NULL)
  290. *LastWhack = '\0';
  291. strcpy(CpDir, Buffer);
  292. strcat(CpDir, "\\print$\\coverpg\\");
  293. } else {
  294. GetServerCpDir( NULL, CpDir, sizeof(CpDir) );
  295. }
  296. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  297. GetWindowsDirectory( CpDir, sizeof(CpDir) );
  298. strcat( CpDir, "\\spool\\fax\\coverpg\\" );
  299. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  300. #else
  301. GetServerCpDir( Buffer[0] ? Buffer : NULL, CpDir, sizeof(CpDir) );
  302. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  303. if (!FaxConfig->ServerCpOnly) {
  304. GetClientCpDir( CpDir, sizeof(CpDir) );
  305. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  306. }
  307. #endif
  308. strcpy( Buffer, FaxConfig->CoverPageName );
  309. if ( ! FaxConfig->ServerCoverPage )
  310. {
  311. char szPersonal[30];
  312. LoadString( FaxXphInstance, IDS_PERSONAL, szPersonal, 30 );
  313. strcat( Buffer, (char *) " " );
  314. strcat( Buffer, szPersonal );
  315. }
  316. Selection = (DWORD)SendMessage( hwndListCov, LB_FINDSTRING, 0, (LPARAM) Buffer );
  317. if (Selection == LB_ERR) {
  318. Selection = 0;
  319. }
  320. SendMessage( hwndListCov, LB_SETCURSEL, (WPARAM) Selection, 0 );
  321. break;
  322. case ( WM_PAINT ) :
  323. if (BeginPaint( hDlg, &ps )) {
  324. DrawSampleText( hDlg, ps.hdc, FaxConfig );
  325. EndPaint( hDlg, &ps );
  326. }
  327. break;
  328. case WM_COMMAND:
  329. if (HIWORD(wParam) == BN_CLICKED) {
  330. if (LOWORD(wParam) == IDC_USE_COVERPAGE) {
  331. if (IsDlgButtonChecked( hDlg, IDC_USE_COVERPAGE ) == BST_CHECKED) {
  332. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), TRUE );
  333. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST_LABEL ), TRUE );
  334. } else {
  335. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), FALSE );
  336. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST_LABEL ), FALSE );
  337. }
  338. return FALSE;
  339. }
  340. }
  341. if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_PRINTER_LIST) {
  342. char SelectedPrinter[50];
  343. //
  344. // delete the old items from the list
  345. //
  346. SendMessage(hwndListCov, LB_RESETCONTENT, 0, 0);
  347. Selection = (DWORD)SendMessage( hwndListPrn, CB_GETCURSEL, 0, 0 );
  348. SendMessage( hwndListPrn, CB_GETLBTEXT, Selection, (LPARAM) SelectedPrinter );
  349. Buffer[0] = 0;
  350. PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &CountPrinters, PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS );
  351. if (PrinterInfo) {
  352. DWORD i;
  353. for (i=0; i<CountPrinters; i++) {
  354. if (strcmp( PrinterInfo[i].pDriverName, FAX_DRIVER_NAME ) == 0) {
  355. if (strcmp( PrinterInfo[i].pPrinterName, SelectedPrinter ) == 0) {
  356. if (PrinterInfo[i].pServerName) {
  357. strcpy( Buffer, PrinterInfo[i].pServerName );
  358. }
  359. }
  360. }
  361. }
  362. MemFree( PrinterInfo );
  363. }
  364. #ifndef WIN95
  365. GetServerCpDir( Buffer[0] ? Buffer : NULL, CpDir, sizeof(CpDir) );
  366. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  367. BOOL ServerChanged = FALSE;
  368. if (!FaxConfig->ServerName) {
  369. if (Buffer[0]) {
  370. ServerChanged = TRUE;
  371. }
  372. } else if (strcmp(Buffer,FaxConfig->ServerName) != 0) {
  373. ServerChanged = TRUE;
  374. }
  375. if (ServerChanged) {
  376. //
  377. // refresh server name
  378. //
  379. if (FaxConfig->ServerName) MemFree(FaxConfig->ServerName);
  380. FaxConfig->ServerName = Buffer[0] ? StringDup(Buffer) : NULL ;
  381. HANDLE hFax;
  382. PFAX_CONFIGURATION pFaxConfiguration;
  383. //
  384. // get the servercp flag
  385. //
  386. FaxConfig->ServerCpOnly = FALSE;
  387. if (FaxConnectFaxServer(FaxConfig->ServerName,&hFax) ){
  388. if (FaxGetConfiguration(hFax,&pFaxConfiguration) ) {
  389. FaxConfig->ServerCpOnly = pFaxConfiguration->ServerCp;
  390. FaxFreeBuffer(pFaxConfiguration);
  391. }
  392. FaxClose(hFax);
  393. }
  394. }
  395. //
  396. // don't add client coverpages if FaxConfig->ServerCpOnly is set to true
  397. //
  398. if (! FaxConfig->ServerCpOnly) {
  399. GetClientCpDir( CpDir, sizeof(CpDir) );
  400. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  401. }
  402. #else
  403. if (Buffer[0]) {
  404. strcpy(CpDir, Buffer);
  405. strcat(CpDir, "\\print$\\coverpg\\");
  406. } else {
  407. GetServerCpDir( NULL, CpDir, sizeof(CpDir) );
  408. }
  409. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  410. GetWindowsDirectory( CpDir, sizeof(CpDir) );
  411. strcat( CpDir, "\\spool\\fax\\coverpg\\" );
  412. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  413. #endif
  414. }
  415. switch (wParam) {
  416. case IDC_SET_FONT:
  417. {
  418. CHOOSEFONT cf;
  419. LOGFONT FontStruct;
  420. CopyMemory( &FontStruct, &FaxConfig->FontStruct, sizeof(LOGFONT) );
  421. cf.lStructSize = sizeof(CHOOSEFONT);
  422. cf.hwndOwner = hDlg;
  423. cf.lpLogFont = &FontStruct;
  424. cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
  425. cf.rgbColors = 0;
  426. cf.lCustData = 0;
  427. cf.lpfnHook = NULL;
  428. cf.lpTemplateName = NULL;
  429. cf.hInstance = NULL;
  430. cf.lpszStyle = NULL;
  431. cf.nFontType = SCREEN_FONTTYPE;
  432. cf.nSizeMin = 0;
  433. cf.nSizeMax = 0;
  434. if (ChooseFont(&cf)) {
  435. CopyMemory( &FaxConfig->FontStruct, &FontStruct, sizeof(LOGFONT) );
  436. InvalidateRect(hDlg, NULL, TRUE);
  437. UpdateWindow( hDlg );
  438. }
  439. }
  440. break;
  441. case IDOK :
  442. FaxConfig->UseCoverPage = IsDlgButtonChecked( hDlg, IDC_USE_COVERPAGE ) == BST_CHECKED;
  443. Selection = (DWORD)SendMessage( hwndListPrn, CB_GETCURSEL, 0, 0 );
  444. SendMessage( hwndListPrn, CB_GETLBTEXT, Selection, (LPARAM) Buffer );
  445. MemFree( FaxConfig->PrinterName );
  446. FaxConfig->PrinterName = StringDup( Buffer );
  447. Selection = (DWORD)SendMessage( hwndListCov, LB_GETCURSEL, 0, 0 );
  448. SendMessage( hwndListCov, LB_GETTEXT, Selection, (LPARAM) Buffer );
  449. MemFree( FaxConfig->CoverPageName );
  450. p = strrchr( Buffer, '(' );
  451. if (p) {
  452. p[-1] = 0;
  453. FaxConfig->ServerCoverPage = FALSE;
  454. } else {
  455. FaxConfig->ServerCoverPage = TRUE;
  456. }
  457. FaxConfig->CoverPageName = StringDup( Buffer );
  458. EndDialog( hDlg, TRUE );
  459. break;
  460. case IDCANCEL:
  461. EndDialog( hDlg, TRUE );
  462. break;
  463. }
  464. break;
  465. case WM_HELP:
  466. case WM_CONTEXTMENU:
  467. FAXWINHELP( message, wParam, lParam, faxextHelpIDs );
  468. break;
  469. }
  470. return FALSE;
  471. }