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.

405 lines
12 KiB

  1. //************************************************************************
  2. // Generic Win 3.1 fax printer driver support. User Interface functions
  3. // which are called by WINSPOOL. Support for Two new entry points required
  4. // by the Win 95 printer UI, DrvDocumentPropertySheets and
  5. // DrvDevicePropertySheets
  6. //
  7. // History:
  8. // 24-Apr-96 reedb created.
  9. //
  10. //************************************************************************
  11. #include "windows.h"
  12. #include "wowfaxui.h"
  13. #include "wfsheets.h"
  14. #include "winspool.h"
  15. //************************************************************************
  16. // Globals
  17. //************************************************************************
  18. extern HINSTANCE ghInst;
  19. DEVMODEW gdmDefaultDevMode;
  20. LONG DrvDocumentProperties(HWND hwnd, HANDLE hPrinter, PWSTR pDeviceName, PDEVMODE pdmOut, PDEVMODE pdmIn, DWORD fMode);
  21. LONG SimpleDocumentProperties(PDOCUMENTPROPERTYHEADER pDPHdr);
  22. //************************************************************************
  23. // NullDlgProc - Procedure for handling "Printer Properties" property
  24. // sheet page
  25. //************************************************************************
  26. BOOL NullDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  27. {
  28. return FALSE;
  29. }
  30. //************************************************************************
  31. // FaxOptionsProc - Procedure for handling "Fax Options" property
  32. // sheet page
  33. //************************************************************************
  34. BOOL FaxOptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  35. {
  36. PDEVMODE pdmOut = NULL;
  37. PDEVMODE pdmIn = NULL;
  38. PUIDATA pUiData;
  39. TCHAR szFeedBack[WOWFAX_MAX_USER_MSG_LEN];
  40. switch (message) {
  41. case WM_INITDIALOG:
  42. SetWindowLong(hDlg, DWL_USER, ((PROPSHEETPAGE *) lParam)->lParam);
  43. return TRUE;
  44. case WM_COMMAND:
  45. if (wParam == IDOK) {
  46. SetWindowText(GetDlgItem(hDlg, IDC_FEEDBACK), L"");
  47. pUiData = (PUIDATA) GetWindowLong(hDlg, DWL_USER);
  48. DrvDocumentProperties(hDlg,
  49. pUiData->hPrinter,
  50. pUiData->pDeviceName,
  51. pUiData->pdmOut,
  52. pUiData->pdmIn,
  53. pUiData->fMode);
  54. //
  55. // Provide user with feedback text.
  56. //
  57. if (LoadString(ghInst, WOWFAX_ENABLE_CONFIG_STR,
  58. szFeedBack, sizeof( szFeedBack)/sizeof(TCHAR))) {
  59. SetWindowText(GetDlgItem(hDlg, IDC_FEEDBACK), szFeedBack);
  60. }
  61. }
  62. break;
  63. case WM_NOTIFY:
  64. if (((NMHDR *) lParam)->code == PSN_APPLY) {
  65. pUiData = (PUIDATA) GetWindowLong(hDlg, DWL_USER);
  66. //
  67. // HACK: Inform common UI library that user has pressed OK
  68. //
  69. pUiData->pfnComPropSheet(pUiData->hComPropSheet,
  70. CPSFUNC_SET_RESULT,
  71. (LONG) pUiData->hFaxOptsPage,
  72. CPSUI_OK);
  73. return TRUE;
  74. }
  75. break;
  76. }
  77. return FALSE;
  78. }
  79. //************************************************************************
  80. // AddDocPropPages -Add our "Document Properties" pages to the property
  81. // sheet. Returns RUE if successful, FALSE otherwise.
  82. //************************************************************************
  83. BOOL AddDocPropPages(PUIDATA pUiData)
  84. {
  85. PROPSHEETPAGE psp;
  86. LONG result;
  87. //
  88. // "Document Properties" dialog only has one tab - "Fax Options"
  89. //
  90. memset(&psp, 0, sizeof(psp));
  91. psp.dwSize = sizeof(PROPSHEETPAGE);
  92. psp.dwFlags = 0;
  93. psp.hInstance = ghInst;
  94. psp.lParam = (LPARAM) pUiData;
  95. psp.pszTemplate = MAKEINTRESOURCE(IDD_DOCPROP);
  96. psp.pfnDlgProc = FaxOptionsProc;
  97. pUiData->hFaxOptsPage = (HANDLE)
  98. pUiData->pfnComPropSheet(pUiData->hComPropSheet,
  99. CPSFUNC_ADD_PROPSHEETPAGE,
  100. (LPARAM) &psp,
  101. 0);
  102. return (pUiData->hFaxOptsPage != NULL);
  103. }
  104. //************************************************************************
  105. // MyGetPrinter - Wrapper function for GetPrinter spooler API. Returns
  106. // Pointer to a PRINTER_INFO_x structure, NULL if there is an error
  107. //************************************************************************
  108. PVOID MyGetPrinter(HANDLE hPrinter, DWORD level)
  109. {
  110. PBYTE pPrinterInfo = NULL;
  111. DWORD cbNeeded;
  112. if (!GetPrinter(hPrinter, level, NULL, 0, &cbNeeded) &&
  113. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  114. (pPrinterInfo = LocalAlloc(LPTR, cbNeeded)) &&
  115. GetPrinter(hPrinter, level, pPrinterInfo, cbNeeded, &cbNeeded))
  116. {
  117. return pPrinterInfo;
  118. }
  119. LOGDEBUG(0, (L"GetPrinter failed\n"));
  120. LocalFree(pPrinterInfo);
  121. return NULL;
  122. }
  123. //************************************************************************
  124. // FreeUiData - Free the data structure used by the fax driver user
  125. // interface.
  126. //************************************************************************
  127. PUIDATA FreeUiData(PUIDATA pUiData)
  128. {
  129. if (pUiData) {
  130. if (pUiData->pDeviceName) LocalFree(pUiData->pDeviceName);
  131. if (pUiData->pDriverName) LocalFree(pUiData->pDriverName);
  132. }
  133. return NULL;
  134. }
  135. //************************************************************************
  136. // FillUiData - Fill in the data structure used by the fax driver user
  137. // interface. Returns pointer to UIDATA structure, NULL if error.
  138. //************************************************************************
  139. PUIDATA FillUiData(HANDLE hPrinter, PDEVMODE pdmInput, PDEVMODE pdmOutput, DWORD fMode)
  140. {
  141. PRINTER_INFO_2 *pPrinterInfo2 = NULL;
  142. PUIDATA pUiData;
  143. //
  144. // Allocate memory to hold UIDATA structure
  145. // Get printer info from the spooler. Copy the driver name.
  146. //
  147. if (! (pUiData = LocalAlloc(LPTR, sizeof(UIDATA))) ||
  148. ! (pPrinterInfo2 = MyGetPrinter(hPrinter, 2)) ||
  149. ! (pUiData->pDeviceName = DupTokenW(pPrinterInfo2->pPrinterName)) ||
  150. ! (pUiData->pDriverName = DupTokenW(pPrinterInfo2->pDriverName))) {
  151. pUiData = FreeUiData(pUiData);
  152. }
  153. else {
  154. pUiData->pdmIn = pdmInput;
  155. pUiData->pdmOut = pdmOutput;
  156. pUiData->fMode = fMode;
  157. pUiData->startUiData = pUiData->endUiData = pUiData;
  158. pUiData->hPrinter = hPrinter;
  159. }
  160. if (pPrinterInfo2)
  161. LocalFree(pPrinterInfo2);
  162. return pUiData;
  163. }
  164. //************************************************************************
  165. // DrvDocumentPropertySheets - Display "Document Properties" property
  166. // sheets. Return > 0 if successful, <= 0 if failed.
  167. //************************************************************************
  168. LONG DrvDocumentPropertySheets(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam)
  169. {
  170. PDOCUMENTPROPERTYHEADER pDPHdr;
  171. PCOMPROPSHEETUI pCompstui;
  172. PUIDATA pUiData;
  173. LONG result;
  174. //
  175. // Validate input parameters
  176. //
  177. if (! (pDPHdr = (PDOCUMENTPROPERTYHEADER) (pPSUIInfo ? pPSUIInfo->lParamInit : lParam))) {
  178. return -1;
  179. }
  180. if (pPSUIInfo == NULL) {
  181. return SimpleDocumentProperties(pDPHdr);
  182. }
  183. //
  184. // Create a UIDATA structure if necessary
  185. //
  186. pUiData = (pPSUIInfo->Reason == PROPSHEETUI_REASON_INIT) ?
  187. FillUiData(pDPHdr->hPrinter, pDPHdr->pdmIn, pDPHdr->pdmOut, pDPHdr->fMode) :
  188. (PUIDATA) pPSUIInfo->UserData;
  189. if (! ValidUiData(pUiData))
  190. return -1;
  191. //
  192. // Handle various cases for which this function might be called
  193. //
  194. switch (pPSUIInfo->Reason) {
  195. case PROPSHEETUI_REASON_INIT:
  196. pUiData->pfnComPropSheet = pPSUIInfo->pfnComPropSheet;
  197. pUiData->hComPropSheet = pPSUIInfo->hComPropSheet;
  198. //
  199. // Add our page to the property sheet
  200. //
  201. if (AddDocPropPages(pUiData)) {
  202. pPSUIInfo->UserData = (DWORD) pUiData;
  203. pPSUIInfo->Result = CPSUI_CANCEL;
  204. return 1;
  205. }
  206. //
  207. // Clean up properly in case of an error
  208. //
  209. FreeUiData(pUiData);
  210. break;
  211. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  212. { PPROPSHEETUI_INFO_HEADER pPSUIHdr;
  213. pPSUIHdr = (PPROPSHEETUI_INFO_HEADER) lParam;
  214. pPSUIHdr->Flags = PSUIHDRF_PROPTITLE | PSUIHDRF_NOAPPLYNOW;
  215. pPSUIHdr->pTitle = pDPHdr->pszPrinterName;
  216. pPSUIHdr->hInst = ghInst;
  217. pPSUIHdr->IconID = IDI_CPSUI_PRINTER2;
  218. }
  219. return 1;
  220. case PROPSHEETUI_REASON_SET_RESULT:
  221. pPSUIInfo->Result = ((PSETRESULT_INFO) lParam)->Result;
  222. return 1;
  223. case PROPSHEETUI_REASON_DESTROY:
  224. //
  225. // Cleanup properly before exiting
  226. //
  227. FreeUiData(pUiData);
  228. return 1;
  229. }
  230. return -1;
  231. }
  232. //************************************************************************
  233. // DrvDevicePropertySheets - Display "Printer Properties" dialog.
  234. // Return > 0 if successful, <= 0 if failed.
  235. //************************************************************************
  236. LONG DrvDevicePropertySheets(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam)
  237. {
  238. PDEVICEPROPERTYHEADER pDPHdr;
  239. PCOMPROPSHEETUI pCompstui;
  240. PROPSHEETPAGE psp;
  241. LONG result;
  242. //
  243. // Validate input parameters
  244. //
  245. LOGDEBUG(1,(L"DrvDevicePropertySheets: %d\n", pPSUIInfo->Reason));
  246. if (!pPSUIInfo || !(pDPHdr = (PDEVICEPROPERTYHEADER) pPSUIInfo->lParamInit)) {
  247. return -1;
  248. }
  249. //
  250. // Handle various cases for which this function might be called
  251. //
  252. switch (pPSUIInfo->Reason) {
  253. case PROPSHEETUI_REASON_INIT:
  254. //
  255. // "Printer Properties" dialog only has one dummy tab
  256. //
  257. memset(&psp, 0, sizeof(psp));
  258. psp.dwSize = sizeof(PROPSHEETPAGE);
  259. psp.dwFlags = 0;
  260. psp.hInstance = ghInst;
  261. psp.pszTemplate = MAKEINTRESOURCE(IDD_NULLPROP);
  262. psp.pfnDlgProc = NullDlgProc;
  263. if (pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet,
  264. CPSFUNC_ADD_PROPSHEETPAGE,
  265. (LPARAM) &psp,
  266. 0))
  267. {
  268. pPSUIInfo->Result = CPSUI_CANCEL;
  269. return 1;
  270. }
  271. break;
  272. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  273. { PPROPSHEETUI_INFO_HEADER pPSUIHdr;
  274. pPSUIHdr = (PPROPSHEETUI_INFO_HEADER) lParam;
  275. pPSUIHdr->Flags = PSUIHDRF_PROPTITLE | PSUIHDRF_NOAPPLYNOW;
  276. pPSUIHdr->pTitle = pDPHdr->pszPrinterName;
  277. pPSUIHdr->hInst = ghInst;
  278. pPSUIHdr->IconID = IDI_CPSUI_FAX;
  279. }
  280. return 1;
  281. case PROPSHEETUI_REASON_SET_RESULT:
  282. pPSUIInfo->Result = ((PSETRESULT_INFO) lParam)->Result;
  283. return 1;
  284. case PROPSHEETUI_REASON_DESTROY:
  285. return 1;
  286. }
  287. return -1;
  288. }
  289. LONG
  290. SimpleDocumentProperties(PDOCUMENTPROPERTYHEADER pDPHdr)
  291. /*++
  292. Routine Description:
  293. Handle simple "Document Properties" where we don't need to display
  294. a dialog and therefore don't have to have common UI library involved
  295. Arguments:
  296. pDPHdr - Points to a DOCUMENTPROPERTYHEADER structure
  297. Return Value:
  298. > 0 if successful, <= 0 otherwise
  299. --*/
  300. {
  301. LONG lRet;
  302. lRet = DrvDocumentProperties(NULL,
  303. pDPHdr->hPrinter,
  304. pDPHdr->pszPrinterName,
  305. pDPHdr->pdmOut,
  306. pDPHdr->pdmIn,
  307. pDPHdr->fMode);
  308. if (pDPHdr->fMode == 0 || pDPHdr->pdmOut == NULL) {
  309. pDPHdr->cbOut = lRet;
  310. }
  311. return lRet;
  312. }