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.

518 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. userinfo.c
  5. Abstract:
  6. Functions for handling events in the "User Info" tab of
  7. the fax client 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 <windows.h>
  17. #include <windowsx.h>
  18. #include <winspool.h>
  19. #include "faxutil.h"
  20. #include "faxreg.h"
  21. #include "faxcfgrs.h"
  22. #include "faxhelp.h"
  23. #include "faxcfg.h"
  24. #include "devmode.h"
  25. #define FAX_DRIVER_NAME TEXT("Windows NT Fax Driver")
  26. BOOL insideSetDlgItemText;
  27. DWORD changeFlag;
  28. VOID
  29. LimitTextFields(
  30. HWND hDlg,
  31. INT *pLimitInfo
  32. )
  33. ;
  34. #if 0
  35. /*++
  36. Routine Description:
  37. Limit the maximum length for a number of text fields
  38. Arguments:
  39. hDlg - Specifies the handle to the dialog window
  40. pLimitInfo - Array of text field control IDs and their maximum length
  41. ID for the 1st text field, maximum length for the 1st text field
  42. ID for the 2nd text field, maximum length for the 2nd text field
  43. ...
  44. 0
  45. Note: The maximum length counts the NUL-terminator.
  46. Return Value:
  47. NONE
  48. --*/
  49. {
  50. while (*pLimitInfo != 0) {
  51. SendDlgItemMessage(hDlg, pLimitInfo[0], EM_SETLIMITTEXT, pLimitInfo[1]-1, 0);
  52. pLimitInfo += 2;
  53. }
  54. }
  55. #endif
  56. VOID
  57. DoInitUserInfo(
  58. HWND hDlg
  59. )
  60. /*++
  61. Routine Description:
  62. Initializes the User Info property sheet page with information from the registry
  63. Arguments:
  64. hDlg - Handle to the User Info property sheet page
  65. Return Value:
  66. NONE
  67. --*/
  68. #define InitUserInfoTextField(id, pValueName){ \
  69. LPWSTR regStr = GetRegistryString(hRegKey, pValueName, L"");\
  70. SetDlgItemText(hDlg, id, regStr);\
  71. MemFree(regStr);}
  72. {
  73. HKEY hRegKey;
  74. //
  75. // Maximum length for various text fields in the dialog
  76. //
  77. static INT textLimits[] = {
  78. IDC_SENDER_NAME, 128,
  79. IDC_SENDER_FAX_NUMBER, 64,
  80. IDC_SENDER_MAILBOX, MAX_EMAIL_ADDRESS,
  81. IDC_SENDER_COMPANY, 128,
  82. IDC_SENDER_ADDRESS, 256,
  83. IDC_SENDER_TITLE, 64,
  84. IDC_SENDER_DEPT, 64,
  85. IDC_SENDER_OFFICE_LOC, 64,
  86. IDC_SENDER_OFFICE_TL, 64,
  87. IDC_SENDER_HOME_TL, 64,
  88. IDC_SENDER_BILLING_CODE, 16,
  89. 0,
  90. };
  91. LimitTextFields(hDlg, textLimits);
  92. //
  93. // Open the user info registry key for reading
  94. //
  95. if (! (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER,REGKEY_FAX_USERINFO,TRUE,KEY_ALL_ACCESS)))
  96. return;
  97. //
  98. // Initialize the list of countries
  99. //
  100. insideSetDlgItemText = TRUE;
  101. //
  102. // Fill in the edit text fields
  103. //
  104. InitUserInfoTextField(IDC_SENDER_NAME, REGVAL_FULLNAME);
  105. InitUserInfoTextField(IDC_SENDER_FAX_NUMBER, REGVAL_FAX_NUMBER);
  106. InitUserInfoTextField(IDC_SENDER_MAILBOX, REGVAL_MAILBOX);
  107. InitUserInfoTextField(IDC_SENDER_COMPANY, REGVAL_COMPANY);
  108. InitUserInfoTextField(IDC_SENDER_TITLE, REGVAL_TITLE);
  109. InitUserInfoTextField(IDC_SENDER_ADDRESS, REGVAL_ADDRESS);
  110. InitUserInfoTextField(IDC_SENDER_DEPT, REGVAL_DEPT);
  111. InitUserInfoTextField(IDC_SENDER_OFFICE_LOC, REGVAL_OFFICE);
  112. InitUserInfoTextField(IDC_SENDER_HOME_TL, REGVAL_HOME_PHONE);
  113. InitUserInfoTextField(IDC_SENDER_OFFICE_TL, REGVAL_OFFICE_PHONE);
  114. InitUserInfoTextField(IDC_SENDER_BILLING_CODE, REGVAL_BILLING_CODE);
  115. insideSetDlgItemText = FALSE;
  116. //
  117. // Close the registry key before returning to the caller
  118. //
  119. RegCloseKey(hRegKey);
  120. }
  121. PVOID
  122. MyGetPrinter(
  123. HANDLE hPrinter,
  124. DWORD level
  125. )
  126. ;
  127. #if 0
  128. /*++
  129. Routine Description:
  130. Wrapper function for GetPrinter spooler API
  131. Arguments:
  132. hPrinter - Identifies the printer in question
  133. level - Specifies the level of PRINTER_INFO_x structure requested
  134. Return Value:
  135. Pointer to a PRINTER_INFO_x structure, NULL if there is an error
  136. --*/
  137. {
  138. PBYTE pPrinterInfo = NULL;
  139. DWORD cbNeeded;
  140. if (!GetPrinter(hPrinter, level, NULL, 0, &cbNeeded) &&
  141. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  142. (pPrinterInfo = MemAlloc(cbNeeded)) &&
  143. GetPrinter(hPrinter, level, pPrinterInfo, cbNeeded, &cbNeeded))
  144. {
  145. return pPrinterInfo;
  146. }
  147. DebugPrint((TEXT("GetPrinter failed: %d\n"), GetLastError()));
  148. MemFree(pPrinterInfo);
  149. return NULL;
  150. }
  151. #endif
  152. BOOL
  153. SetPrinterDevMode(
  154. LPTSTR ServerName,
  155. LPTSTR PrinterName,
  156. LPTSTR billingCode,
  157. LPTSTR emailAddress
  158. )
  159. {
  160. HANDLE hPrinter = NULL;
  161. TCHAR PrinterBuffer[100];
  162. PPRINTER_INFO_9 pPrinterInfo9 = NULL;
  163. PPRINTER_INFO_2 pPrinterInfo2 = NULL;
  164. PDRVDEVMODE dm = NULL;
  165. PRINTER_DEFAULTS PrinterDefaults = {NULL, NULL, PRINTER_ALL_ACCESS};
  166. BOOL bSuccess = FALSE;
  167. if (ServerName) {
  168. wsprintf(PrinterBuffer,TEXT("\\\\%s\\%s"),ServerName,PrinterName);
  169. } else {
  170. wsprintf(PrinterBuffer,TEXT("%s"),PrinterName);
  171. }
  172. if (!OpenPrinter(PrinterBuffer,&hPrinter,&PrinterDefaults)) {
  173. DebugPrint(( TEXT("OpenPrinter failed, ec = %d\n"), GetLastError() ));
  174. goto exit;
  175. }
  176. //
  177. // Get the current user devmode
  178. //
  179. pPrinterInfo9 = MyGetPrinter(hPrinter,9);
  180. if (!pPrinterInfo9) {
  181. goto exit;
  182. }
  183. if (!pPrinterInfo9->pDevMode) {
  184. //
  185. // User devmode does not exist, so create devmode based on the printer devmode
  186. //
  187. pPrinterInfo2 = MyGetPrinter(hPrinter,2);
  188. if (!pPrinterInfo2 || !pPrinterInfo2->pDevMode) {
  189. goto exit;
  190. }
  191. dm = (PDRVDEVMODE) MemAlloc(sizeof(DRVDEVMODE));
  192. if (!dm) {
  193. goto exit;
  194. }
  195. //
  196. // Copy the printer devmode to the public devmode section of the user devmode
  197. //
  198. CopyMemory(&dm->dmPublic, pPrinterInfo2->pDevMode, sizeof(DEVMODE));
  199. dm->dmPublic.dmDriverExtra = sizeof(DMPRIVATE);
  200. //
  201. // Set the private devmode section of the user devmode
  202. //
  203. dm->dmPrivate.signature = DRIVER_SIGNATURE;
  204. dm->dmPrivate.flags = 0;
  205. dm->dmPrivate.sendCoverPage = TRUE;
  206. dm->dmPrivate.whenToSend = SENDFAX_ASAP;
  207. //
  208. // Set the billing code and email address
  209. //
  210. lstrcpy(dm->dmPrivate.billingCode,billingCode);
  211. lstrcpy(dm->dmPrivate.emailAddress,emailAddress);
  212. //
  213. // Patch up the pointer to the user devmode
  214. //
  215. pPrinterInfo9->pDevMode = (PDEVMODE) dm;
  216. }
  217. else {
  218. //
  219. // User devmode does exist, so be sure not to overwrite existing settings
  220. //
  221. dm = (PDRVDEVMODE) pPrinterInfo9->pDevMode;
  222. if (billingCode[0] && !dm->dmPrivate.billingCode[0]) {
  223. lstrcpy(dm->dmPrivate.billingCode,billingCode);
  224. }
  225. if (emailAddress[0] && !dm->dmPrivate.emailAddress[0]) {
  226. lstrcpy(dm->dmPrivate.emailAddress,emailAddress);
  227. }
  228. }
  229. //
  230. // Set the user devmode
  231. //
  232. if (!SetPrinter(hPrinter,9,(LPBYTE)pPrinterInfo9,0)) {
  233. DebugPrint(( TEXT("SetPrinter failed, ec = %d\n"), GetLastError() ));
  234. goto exit;
  235. }
  236. bSuccess = TRUE;
  237. exit:
  238. if (hPrinter) {
  239. ClosePrinter(hPrinter);
  240. }
  241. if (pPrinterInfo2) {
  242. MemFree( pPrinterInfo2 );
  243. if (dm) {
  244. MemFree(dm);
  245. }
  246. }
  247. if (pPrinterInfo9) {
  248. MemFree( pPrinterInfo9 );
  249. }
  250. return bSuccess;
  251. }
  252. VOID
  253. DoSaveUserInfo(
  254. HWND hDlg
  255. )
  256. /*++
  257. Routine Description:
  258. Save the information on the User Info property sheet page to registry
  259. Arguments:
  260. hDlg - Handle to the User Info property sheet page
  261. Return Value:
  262. NONE
  263. --*/
  264. #define SaveUserInfoTextField(id, pValueName) { \
  265. if (! GetDlgItemText(hDlg, id, buffer, MAX_PATH)) \
  266. buffer[0] = 0; \
  267. SetRegistryString(hRegKey, pValueName, buffer); \
  268. }
  269. #define IsPrinterFaxPrinter(__PrinterInfo) \
  270. ((lstrcmp(__PrinterInfo.pDriverName,FAX_DRIVER_NAME) == 0) ? TRUE : FALSE )
  271. {
  272. WCHAR buffer[MAX_PATH];
  273. HKEY hRegKey;
  274. WCHAR BillingCode[MAX_BILLING_CODE+1];
  275. WCHAR EmailAddress[MAX_EMAIL_ADDRESS+1];
  276. PPRINTER_INFO_2 pPrinterInfo;
  277. DWORD dwPrinters,i;
  278. //
  279. // Open the user registry key for writing and create it if necessary
  280. //
  281. if (! changeFlag ||
  282. ! (hRegKey = OpenRegistryKey(HKEY_CURRENT_USER,REGKEY_FAX_USERINFO,TRUE,KEY_ALL_ACCESS)))
  283. {
  284. return;
  285. }
  286. SaveUserInfoTextField(IDC_SENDER_NAME, REGVAL_FULLNAME);
  287. SaveUserInfoTextField(IDC_SENDER_FAX_NUMBER, REGVAL_FAX_NUMBER);
  288. SaveUserInfoTextField(IDC_SENDER_MAILBOX, REGVAL_MAILBOX);
  289. SaveUserInfoTextField(IDC_SENDER_COMPANY, REGVAL_COMPANY);
  290. SaveUserInfoTextField(IDC_SENDER_TITLE, REGVAL_TITLE);
  291. SaveUserInfoTextField(IDC_SENDER_ADDRESS, REGVAL_ADDRESS);
  292. SaveUserInfoTextField(IDC_SENDER_DEPT, REGVAL_DEPT);
  293. SaveUserInfoTextField(IDC_SENDER_OFFICE_LOC, REGVAL_OFFICE);
  294. SaveUserInfoTextField(IDC_SENDER_HOME_TL, REGVAL_HOME_PHONE);
  295. SaveUserInfoTextField(IDC_SENDER_OFFICE_TL, REGVAL_OFFICE_PHONE);
  296. SaveUserInfoTextField(IDC_SENDER_BILLING_CODE, REGVAL_BILLING_CODE);
  297. //
  298. // Close the registry key before returning to the caller
  299. //
  300. RegCloseKey(hRegKey);
  301. //
  302. // write this information into the devmode for each fax printer
  303. //
  304. pPrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters(NULL,
  305. 2,
  306. &dwPrinters,
  307. PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS
  308. );
  309. if (!pPrinterInfo) {
  310. return;
  311. }
  312. for (i = 0; i<dwPrinters;i++) {
  313. if (IsPrinterFaxPrinter(pPrinterInfo[i])) {
  314. //
  315. // note that we could use the devmode from printer_info_2 structure but we use GetPrinter/SetPrinter
  316. // instead
  317. //
  318. GetDlgItemText( hDlg, IDC_SENDER_BILLING_CODE, BillingCode, sizeof(BillingCode)/sizeof(WCHAR) );
  319. GetDlgItemText( hDlg, IDC_SENDER_MAILBOX, EmailAddress, sizeof(EmailAddress)/sizeof(WCHAR) );
  320. SetPrinterDevMode(pPrinterInfo[i].pServerName,
  321. pPrinterInfo[i].pPrinterName,
  322. BillingCode,
  323. EmailAddress) ;
  324. }
  325. }
  326. }
  327. BOOL
  328. UserInfoDlgProc(
  329. HWND hDlg,
  330. UINT message,
  331. WPARAM wParam,
  332. LPARAM lParam
  333. )
  334. /*++
  335. Routine Description:
  336. Procedure for handling the "User Info" tab
  337. Arguments:
  338. hDlg - Identifies the property sheet page
  339. message - Specifies the message
  340. wParam - Specifies additional message-specific information
  341. lParam - Specifies additional message-specific information
  342. Return Value:
  343. Depends on the value of message parameter
  344. --*/
  345. {
  346. switch (message) {
  347. case WM_INITDIALOG:
  348. //
  349. // Initialize the text fields with information from the registry
  350. //
  351. DoInitUserInfo(hDlg);
  352. return TRUE;
  353. case WM_COMMAND:
  354. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  355. case IDC_SENDER_NAME:
  356. case IDC_SENDER_FAX_NUMBER:
  357. case IDC_SENDER_MAILBOX:
  358. case IDC_SENDER_COMPANY:
  359. case IDC_SENDER_ADDRESS:
  360. case IDC_SENDER_TITLE:
  361. case IDC_SENDER_DEPT:
  362. case IDC_SENDER_OFFICE_LOC:
  363. case IDC_SENDER_OFFICE_TL:
  364. case IDC_SENDER_HOME_TL:
  365. case IDC_SENDER_BILLING_CODE:
  366. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE && !insideSetDlgItemText)
  367. break;
  368. default:
  369. return FALSE;
  370. }
  371. SetChangedFlag( hDlg, TRUE );
  372. return TRUE;
  373. case WM_NOTIFY:
  374. switch (((NMHDR *) lParam)->code) {
  375. case PSN_SETACTIVE:
  376. break;
  377. case PSN_APPLY:
  378. //
  379. // User pressed OK or Apply - validate inputs and save changes
  380. //
  381. DoSaveUserInfo(hDlg);
  382. SetChangedFlag( hDlg, FALSE );
  383. return PSNRET_NOERROR;
  384. }
  385. break;
  386. case WM_HELP:
  387. case WM_CONTEXTMENU:
  388. return HandleHelpPopup(hDlg, message, wParam, lParam, CLIENT_OPTIONS_PAGE);
  389. }
  390. return FALSE;
  391. }