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.

448 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxopts.c
  5. Abstract:
  6. Functions for handling the Fax Options property sheet page
  7. Environment:
  8. Fax driver user interface
  9. Revision History:
  10. 01/16/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxui.h"
  16. #include "faxhelp.h"
  17. //
  18. // Table for mapping control IDs to help indices
  19. //
  20. static ULONG_PTR faxOptionsHelpIDs[] = {
  21. IDC_SEND_ASAP, IDH_FAXDEFAULT_SEND_ASAP,
  22. IDC_SEND_AT_CHEAP, IDH_FAXDEFAULT_SEND_AT_CHEAP,
  23. IDC_SEND_AT_TIME, IDH_FAXDEFAULT_SEND_AT_TIME,
  24. IDC_PAPER_SIZE, IDH_FAXDEFAULT_PAPER_SIZE,
  25. IDC_IMAGE_QUALITY, IDH_FAXDEFAULT_IMAGE_QUALITY,
  26. IDC_PORTRAIT, IDH_FAXDEFAULT_PORTRAIT,
  27. IDC_LANDSCAPE, IDH_FAXDEFAULT_LANDSCAPE,
  28. IDC_BILLING_CODE, IDH_FAXDEFAULT_BILLING_CODE,
  29. IDC_EMAIL, IDH_FAXDEFAULT_GENERAL_EMAIL_ADDRESS,
  30. IDI_FAX_OPTIONS, (DWORD) -1,
  31. IDC_TITLE, (DWORD) -1,
  32. IDC_FAX_SEND_GRP, IDH_FAXDEFAULT_FAX_SEND_TIME_GRP,
  33. IDC_DEFAULT_PRINT_SETUP_GRP, IDH_FAXDEFAULT_DEFAULT_PRINT_SETUP_GRP,
  34. IDC_ORIENTATION, IDH_FAXDEFAULT_ORIENTATION,
  35. IDC_SENDTIME, IDH_FAXDEFAULT_FAX_SEND_AT_TIME,
  36. 0, 0
  37. };
  38. VOID
  39. DoInitializeFaxOptions(
  40. HWND hDlg,
  41. PUIDATA pUiData
  42. )
  43. /*++
  44. Routine Description:
  45. Initializes the Fax Options property sheet page with information from the registry
  46. Arguments:
  47. hDlg - Handle to the Fax Options property sheet page
  48. pUiData - Points to our UIDATA structure
  49. Return Value:
  50. NONE
  51. --*/
  52. {
  53. PDEVMODE pdmPublic = &pUiData->devmode.dmPublic;
  54. PDMPRIVATE pdmPrivate = &pUiData->devmode.dmPrivate;
  55. TCHAR buffer[MAX_STRING_LEN];
  56. //TCHAR TimeFormat[32];
  57. SYSTEMTIME st;
  58. HWND hwndList,hTimeControl;
  59. INT itemId;
  60. TCHAR Is24H[2], IsRTL[2], *pszTimeFormat = TEXT("h : mm tt");
  61. if (GetLocaleInfo( LOCALE_USER_DEFAULT,LOCALE_ITIME, Is24H,sizeof(Is24H) ) && Is24H[0] == TEXT('1')) {
  62. pszTimeFormat = TEXT("H : mm");
  63. }
  64. else if (GetLocaleInfo( LOCALE_USER_DEFAULT,LOCALE_ITIMEMARKPOSN, IsRTL,sizeof(IsRTL) ) && IsRTL[0] == TEXT('1')) {
  65. pszTimeFormat = TEXT("tt h : mm");
  66. }
  67. //
  68. // Time to send
  69. //
  70. itemId = (pdmPrivate->whenToSend == SENDFAX_AT_CHEAP) ? IDC_SEND_AT_CHEAP :
  71. (pdmPrivate->whenToSend == SENDFAX_AT_TIME) ? IDC_SEND_AT_TIME : IDC_SEND_ASAP;
  72. CheckRadioButton(hDlg, IDC_SEND_ASAP, IDC_SEND_AT_TIME, itemId);
  73. //
  74. // Initialize the send-at time control
  75. //
  76. //LoadString(ghInstance,IDS_WIZ_TIME_FORMAT,TimeFormat,sizeof(TimeFormat));
  77. hTimeControl = GetDlgItem(hDlg, IDC_SENDTIME);
  78. //DateTime_SetFormat( hTimeControl,TimeFormat );
  79. DateTime_SetFormat( hTimeControl,pszTimeFormat );
  80. GetLocalTime(&st);
  81. st.wHour = pdmPrivate->sendAtTime.Hour;
  82. st.wMinute = pdmPrivate->sendAtTime.Minute;
  83. DateTime_SetSystemtime( hTimeControl, GDT_VALID, &st );
  84. EnableWindow(hTimeControl, pdmPrivate->whenToSend == SENDFAX_AT_TIME);
  85. //
  86. // Initialize the print setup controls:
  87. // paper size
  88. // image quality
  89. // orientation
  90. // billing code
  91. //
  92. if (hwndList = GetDlgItem(hDlg, IDC_PAPER_SIZE)) {
  93. LPTSTR pFormName = pUiData->pFormNames;
  94. INT listIdx;
  95. for (itemId=0; itemId < pUiData->cForms; itemId++, pFormName += CCHPAPERNAME) {
  96. if ((listIdx = (INT)SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM) pFormName)) != CB_ERR) {
  97. SendMessage(hwndList, CB_SETITEMDATA, listIdx, itemId);
  98. if (_tcscmp(pFormName, pdmPublic->dmFormName) == EQUAL_STRING)
  99. SendMessage(hwndList, CB_SETCURSEL, listIdx, 0);
  100. }
  101. }
  102. }
  103. if (hwndList = GetDlgItem(hDlg, IDC_IMAGE_QUALITY)) {
  104. LoadString(ghInstance, IDS_QUALITY_NORMAL, buffer, MAX_STRING_LEN);
  105. SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM) buffer);
  106. LoadString(ghInstance, IDS_QUALITY_DRAFT, buffer, MAX_STRING_LEN);
  107. SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM) buffer);
  108. itemId = (pdmPublic->dmYResolution == FAXRES_VERTDRAFT) ? 1 : 0;
  109. SendMessage(hwndList, CB_SETCURSEL, itemId, 0);
  110. }
  111. itemId = (pdmPublic->dmOrientation == DMORIENT_LANDSCAPE) ?
  112. IDC_LANDSCAPE : IDC_PORTRAIT;
  113. CheckDlgButton(hDlg, itemId, TRUE);
  114. SendDlgItemMessage(hDlg, IDC_BILLING_CODE, EM_SETLIMITTEXT, MAX_BILLING_CODE-1, 0);
  115. SetDlgItemText(hDlg, IDC_BILLING_CODE, pdmPrivate->billingCode);
  116. SendDlgItemMessage(hDlg, IDC_EMAIL, EM_SETLIMITTEXT, MAX_EMAIL_ADDRESS-1, 0);
  117. SetDlgItemText(hDlg, IDC_EMAIL, pdmPrivate->emailAddress);
  118. //
  119. // Disable all controls if the user has no permission
  120. //
  121. if (! pUiData->hasPermission) {
  122. EnableWindow(GetDlgItem(hDlg, IDC_SEND_ASAP), FALSE);
  123. EnableWindow(GetDlgItem(hDlg, IDC_SEND_AT_CHEAP), FALSE);
  124. EnableWindow(GetDlgItem(hDlg, IDC_SEND_AT_TIME), FALSE);
  125. EnableWindow(GetDlgItem(hDlg, IDC_PAPER_SIZE), FALSE);
  126. EnableWindow(GetDlgItem(hDlg, IDC_IMAGE_QUALITY), FALSE);
  127. EnableWindow(GetDlgItem(hDlg, IDC_PORTRAIT), FALSE);
  128. EnableWindow(GetDlgItem(hDlg, IDC_LANDSCAPE), FALSE);
  129. EnableWindow(GetDlgItem(hDlg, IDC_BILLING_CODE), FALSE);
  130. EnableWindow(GetDlgItem(hDlg, IDC_EMAIL), FALSE);
  131. }
  132. }
  133. VOID
  134. DoSaveFaxOptions(
  135. HWND hDlg,
  136. PUIDATA pUiData
  137. )
  138. /*++
  139. Routine Description:
  140. Save the information on the Fax Options property sheet page to registry
  141. Arguments:
  142. hDlg - Handle to the Fax Options property sheet page
  143. pUiData - Points to our UIDATA structure
  144. Return Value:
  145. NONE
  146. --*/
  147. {
  148. PDEVMODE pdmPublic = &pUiData->devmode.dmPublic;
  149. PDMPRIVATE pdmPrivate = &pUiData->devmode.dmPrivate;
  150. HWND hwndList;
  151. INT listIdx;
  152. DWORD rVal;
  153. SYSTEMTIME SendTime;
  154. //
  155. // Time to send
  156. //
  157. pdmPrivate->whenToSend =
  158. IsDlgButtonChecked(hDlg, IDC_SEND_AT_CHEAP) ? SENDFAX_AT_CHEAP :
  159. IsDlgButtonChecked(hDlg, IDC_SEND_AT_TIME) ? SENDFAX_AT_TIME : SENDFAX_ASAP;
  160. //
  161. // Retrieve the current settings of send-at time control
  162. //
  163. rVal = DateTime_GetSystemtime(GetDlgItem(hDlg, IDC_SENDTIME), &SendTime);
  164. pdmPrivate->sendAtTime.Hour = SendTime.wHour;
  165. pdmPrivate->sendAtTime.Minute = SendTime.wMinute;
  166. //
  167. // Retrieve the current settings of print setup controls:
  168. // paper size
  169. // image quality
  170. // orientation
  171. // billing code
  172. //
  173. if ((hwndList = GetDlgItem(hDlg, IDC_PAPER_SIZE)) &&
  174. (listIdx = (INT)SendMessage(hwndList, CB_GETCURSEL, 0, 0)) != CB_ERR)
  175. {
  176. listIdx = (INT)SendMessage(hwndList, CB_GETITEMDATA, listIdx, 0);
  177. if (listIdx >= 0 && listIdx < pUiData->cForms) {
  178. pdmPublic->dmFields &= ~(DM_PAPERLENGTH|DM_PAPERWIDTH);
  179. pdmPublic->dmFields |= DM_FORMNAME;
  180. pdmPublic->dmPaperSize = pUiData->pPapers[listIdx];
  181. CopyStringW(pdmPublic->dmFormName,
  182. pUiData->pFormNames + listIdx * CCHPAPERNAME,
  183. CCHFORMNAME);
  184. }
  185. }
  186. pdmPublic->dmPrintQuality = FAXRES_HORIZONTAL;
  187. pdmPublic->dmYResolution =
  188. (SendDlgItemMessage(hDlg, IDC_IMAGE_QUALITY, CB_GETCURSEL, 0, 0) == 1) ?
  189. FAXRES_VERTDRAFT :
  190. FAXRES_VERTICAL;
  191. pdmPublic->dmOrientation =
  192. IsDlgButtonChecked(hDlg, IDC_LANDSCAPE) ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
  193. GetDlgItemText(hDlg, IDC_BILLING_CODE, pdmPrivate->billingCode, MAX_BILLING_CODE);
  194. GetDlgItemText(hDlg, IDC_EMAIL, pdmPrivate->emailAddress, MAX_EMAIL_ADDRESS);
  195. }
  196. INT_PTR
  197. FaxOptionsProc(
  198. HWND hDlg,
  199. UINT message,
  200. WPARAM wParam,
  201. LPARAM lParam
  202. )
  203. /*++
  204. Routine Description:
  205. Procedure for handling Fax Options property sheet page
  206. Arguments:
  207. hDlg - Identifies the property sheet page
  208. message - Specifies the message
  209. wParam - Specifies additional message-specific information
  210. lParam - Specifies additional message-specific information
  211. Return Value:
  212. Depends on the value of message parameter
  213. --*/
  214. {
  215. PUIDATA pUiData;
  216. WORD cmdId;
  217. static BOOL bPortrait;
  218. LPHELPINFO lpHelpInfo;
  219. switch (message) {
  220. case WM_INITDIALOG:
  221. //
  222. // Remember the pointer to our UIDATA structure
  223. //
  224. lParam = ((PROPSHEETPAGE *) lParam)->lParam;
  225. pUiData = (PUIDATA) lParam;
  226. Assert(ValidUiData(pUiData));
  227. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  228. //
  229. // Intitialize the controls with information from the registry
  230. //
  231. DoInitializeFaxOptions(hDlg, pUiData);
  232. bPortrait = IsDlgButtonChecked(hDlg,IDC_PORTRAIT);
  233. return TRUE;
  234. case WM_COMMAND:
  235. switch (cmdId = GET_WM_COMMAND_ID(wParam, lParam)) {
  236. case IDC_SEND_ASAP:
  237. case IDC_SEND_AT_CHEAP:
  238. case IDC_SEND_AT_TIME:
  239. //
  240. // Enable/disable time control depending on whether user
  241. // has chosen to send fax at specific time.
  242. //
  243. EnableWindow(GetDlgItem(hDlg, IDC_SENDTIME), cmdId == IDC_SEND_AT_TIME);
  244. PropSheet_Changed(GetParent(hDlg),hDlg);
  245. return TRUE;
  246. case IDC_SENDTIME:
  247. PropSheet_Changed(GetParent(hDlg),hDlg);
  248. break;
  249. case IDC_BILLING_CODE:
  250. case IDC_EMAIL:
  251. PropSheet_Changed(GetParent(hDlg),hDlg);
  252. break;
  253. };
  254. if (HIWORD(wParam) == CBN_SELCHANGE) {
  255. if (GetDlgCtrlID((HWND)lParam) == IDC_IMAGE_QUALITY ||
  256. GetDlgCtrlID((HWND)lParam) == IDC_PAPER_SIZE ) {
  257. PropSheet_Changed(GetParent(hDlg),hDlg);
  258. }
  259. }
  260. if (HIWORD(wParam) == BN_CLICKED) {
  261. if ((LOWORD(wParam) == IDC_PORTRAIT && !bPortrait) ||
  262. (LOWORD(wParam) == IDC_LANDSCAPE && bPortrait)) {
  263. PropSheet_Changed(GetParent(hDlg),hDlg);
  264. }
  265. }
  266. break;
  267. case WM_NOTIFY:
  268. if (((NMHDR *) lParam)->code == PSN_APPLY) {
  269. pUiData = (PUIDATA) GetWindowLongPtr(hDlg, DWLP_USER);
  270. Assert(ValidUiData(pUiData));
  271. //
  272. // User pressed OK or Apply - validate inputs and save changes
  273. //
  274. DoSaveFaxOptions(hDlg, pUiData);
  275. //
  276. // HACK: Inform common UI library that user has pressed OK
  277. //
  278. pUiData->pfnComPropSheet(pUiData->hComPropSheet,
  279. CPSFUNC_SET_RESULT,
  280. (LPARAM) pUiData->hFaxOptsPage,
  281. CPSUI_OK);
  282. return TRUE;
  283. } else if (((NMHDR *) lParam)->code == DTN_DATETIMECHANGE) {
  284. PropSheet_Changed(GetParent(hDlg),hDlg);
  285. }
  286. break;
  287. case WM_HELP:
  288. lpHelpInfo = (LPHELPINFO) lParam;
  289. if (IsChild(hDlg, lpHelpInfo->hItemHandle)) {
  290. while (GetParent(lpHelpInfo->hItemHandle) != hDlg) {
  291. lpHelpInfo->hItemHandle = GetParent(lpHelpInfo->hItemHandle);
  292. }
  293. }
  294. case WM_CONTEXTMENU:
  295. FAXWINHELP(message, wParam, lParam, faxOptionsHelpIDs);
  296. /*++
  297. pUiData = (PUIDATA) GetWindowLongPtr(hDlg, DWLP_USER);
  298. if (ValidUiData(pUiData) && pUiData->pHelpFile) {
  299. HWND hwndHelp;
  300. INT helpCommand;
  301. if (message == WM_HELP) {
  302. hwndHelp = ((LPHELPINFO) lParam)->hItemHandle;
  303. helpCommand = HELP_WM_HELP;
  304. } else {
  305. hwndHelp = (HWND) wParam;
  306. helpCommand = HELP_CONTEXTMENU;
  307. }
  308. WinHelp(hwndHelp, pUiData->pHelpFile, helpCommand, (ULONG_PTR) faxOptionsHelpIDs);
  309. } else
  310. Assert(FALSE);
  311. --*/
  312. break;
  313. }
  314. return FALSE;
  315. }