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.

344 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxdm.c
  5. Abstract:
  6. Functions for dealing with devmodes
  7. Environment:
  8. Fax driver, user and kernel mode
  9. Revision History:
  10. 01/09/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxlib.h"
  16. VOID
  17. DriverDefaultDevmode(
  18. PDRVDEVMODE pdm,
  19. LPTSTR pDeviceName,
  20. HANDLE hPrinter
  21. )
  22. /*++
  23. Routine Description:
  24. Return the driver's default devmode
  25. Arguments:
  26. pdm - Specifies a buffer for storing driver default devmode
  27. pDeviceName - Points to device name string
  28. hPrinter - Handle to the printer object
  29. Return Value:
  30. NONE
  31. --*/
  32. {
  33. #ifndef KERNEL_MODE
  34. PDMPRIVATE dmPrivate;
  35. PDRVDEVMODE dmSource;
  36. #endif
  37. //
  38. // Default value for public devmode fields
  39. //
  40. memset(pdm, 0, sizeof(DRVDEVMODE));
  41. if (pDeviceName == NULL)
  42. pDeviceName = DRIVER_NAME;
  43. CopyString(pdm->dmPublic.dmDeviceName, pDeviceName, CCHDEVICENAME);
  44. pdm->dmPublic.dmDriverVersion = DRIVER_VERSION;
  45. pdm->dmPublic.dmSpecVersion = DM_SPECVERSION;
  46. pdm->dmPublic.dmSize = sizeof(DEVMODE);
  47. pdm->dmPublic.dmDriverExtra = sizeof(DMPRIVATE);
  48. pdm->dmPublic.dmFields = DM_ORIENTATION |
  49. DM_PAPERSIZE |
  50. DM_FORMNAME |
  51. DM_COPIES |
  52. DM_PRINTQUALITY |
  53. DM_YRESOLUTION |
  54. DM_DEFAULTSOURCE;
  55. pdm->dmPublic.dmOrientation = DMORIENT_PORTRAIT;
  56. pdm->dmPublic.dmCopies = 1;
  57. pdm->dmPublic.dmScale = 100;
  58. pdm->dmPublic.dmPrintQuality = FAXRES_HORIZONTAL;
  59. pdm->dmPublic.dmYResolution = FAXRES_VERTICAL;
  60. pdm->dmPublic.dmDuplex = DMDUP_SIMPLEX;
  61. pdm->dmPublic.dmCollate = DMCOLLATE_FALSE;
  62. pdm->dmPublic.dmTTOption = DMTT_BITMAP;
  63. pdm->dmPublic.dmColor = DMCOLOR_MONOCHROME;
  64. pdm->dmPublic.dmDefaultSource = DMBIN_ONLYONE;
  65. if (hPrinter && GetPrinterDataDWord(hPrinter, PRNDATA_ISMETRIC, 0)) {
  66. pdm->dmPublic.dmPaperSize = DMPAPER_A4;
  67. CopyString(pdm->dmPublic.dmFormName, FORMNAME_A4, CCHFORMNAME);
  68. } else {
  69. pdm->dmPublic.dmPaperSize = DMPAPER_LETTER;
  70. CopyString(pdm->dmPublic.dmFormName, FORMNAME_LETTER, CCHFORMNAME);
  71. }
  72. //
  73. // Private devmode fields
  74. //
  75. #ifdef KERNEL_MODE
  76. pdm->dmPrivate.signature = DRIVER_SIGNATURE;
  77. pdm->dmPrivate.flags = 0;
  78. pdm->dmPrivate.sendCoverPage = TRUE;
  79. pdm->dmPrivate.whenToSend = SENDFAX_ASAP;
  80. #else
  81. dmSource = (PDRVDEVMODE) GetPerUserDevmode(NULL);
  82. if (!dmSource) {
  83. //
  84. // default values
  85. //
  86. pdm->dmPrivate.signature = DRIVER_SIGNATURE;
  87. pdm->dmPrivate.flags = 0;
  88. pdm->dmPrivate.sendCoverPage = TRUE;
  89. pdm->dmPrivate.whenToSend = SENDFAX_ASAP;
  90. } else {
  91. dmPrivate = &dmSource->dmPrivate;
  92. pdm->dmPrivate.signature = dmPrivate->signature;//DRIVER_SIGNATURE;
  93. pdm->dmPrivate.flags = dmPrivate->flags;// 0;
  94. pdm->dmPrivate.sendCoverPage = dmPrivate->sendCoverPage; //TRUE;
  95. pdm->dmPrivate.whenToSend = dmPrivate->whenToSend;//SENDFAX_ASAP;
  96. pdm->dmPrivate.sendAtTime = dmPrivate->sendAtTime;
  97. CopyString(pdm->dmPrivate.billingCode,dmPrivate->billingCode,MAX_BILLING_CODE);
  98. CopyString(pdm->dmPrivate.emailAddress,dmPrivate->emailAddress,MAX_EMAIL_ADDRESS);
  99. MemFree(dmSource);
  100. }
  101. #endif
  102. }
  103. BOOL
  104. MergeDevmode(
  105. PDRVDEVMODE pdmDest,
  106. PDEVMODE pdmSrc,
  107. BOOL publicOnly
  108. )
  109. /*++
  110. Routine Description:
  111. Merge the source devmode into the destination devmode
  112. Arguments:
  113. pdmDest - Specifies the destination devmode
  114. pdmSrc - Specifies the source devmode
  115. publicOnly - Only merge public portion of the devmode
  116. Return Value:
  117. TRUE if successful, FALSE if the source devmode is invalid
  118. [Note:]
  119. pdmDest must point to a valid current-version devmode
  120. --*/
  121. #define BadDevmode(reason) { Error(("Invalid DEVMODE: %s\n", reason)); valid = FALSE; }
  122. {
  123. PDEVMODE pdmIn, pdmOut, pdmAlloced = NULL;
  124. PDMPRIVATE pdmPrivate;
  125. BOOL valid = TRUE;
  126. //
  127. // If there is no source devmode, levae destination devmode untouched
  128. //
  129. if ((pdmIn = pdmSrc) == NULL)
  130. return TRUE;
  131. //
  132. // Convert source devmode to current version if necessary
  133. //
  134. if (! CurrentVersionDevmode(pdmIn)) {
  135. Warning(("Converting non-current version DEVMODE ...\n"));
  136. if (! (pdmIn = pdmAlloced = MemAlloc(sizeof(DRVDEVMODE)))) {
  137. Error(("Memory allocation failed\n"));
  138. return FALSE;
  139. }
  140. Assert(pdmDest->dmPublic.dmSize == sizeof(DEVMODE) &&
  141. pdmDest->dmPublic.dmDriverExtra == sizeof(DMPRIVATE));
  142. memcpy(pdmIn, pdmDest, sizeof(DRVDEVMODE));
  143. if (ConvertDevmode(pdmSrc, pdmIn) <= 0) {
  144. Error(("ConvertDevmode failed\n"));
  145. MemFree(pdmAlloced);
  146. return FALSE;
  147. }
  148. }
  149. //
  150. // If the input devmode is the same as the driver default,
  151. // there is no need to merge it.
  152. //
  153. pdmPrivate = &((PDRVDEVMODE) pdmIn)->dmPrivate;
  154. if (pdmPrivate->signature == DRIVER_SIGNATURE &&
  155. (pdmPrivate->flags & FAXDM_DRIVER_DEFAULT))
  156. {
  157. Verbose(("Merging driver default devmode.\n"));
  158. }
  159. else
  160. {
  161. //
  162. // Merge source devmode into destination devmode
  163. //
  164. pdmOut = &pdmDest->dmPublic;
  165. //
  166. // Device name: Always the same as printer name
  167. //
  168. // CopyString(pdmOut->dmDeviceName, pdmIn->dmDeviceName, CCHDEVICENAME);
  169. //
  170. // Orientation
  171. //
  172. if (pdmIn->dmFields & DM_ORIENTATION) {
  173. if (pdmIn->dmOrientation == DMORIENT_PORTRAIT ||
  174. pdmIn->dmOrientation == DMORIENT_LANDSCAPE)
  175. {
  176. pdmOut->dmFields |= DM_ORIENTATION;
  177. pdmOut->dmOrientation = pdmIn->dmOrientation;
  178. } else
  179. BadDevmode("orientation");
  180. }
  181. //
  182. // Form selection
  183. //
  184. if (pdmIn->dmFields & DM_PAPERSIZE) {
  185. if (pdmIn->dmPaperSize >= DMPAPER_FIRST) {
  186. pdmOut->dmFields |= DM_PAPERSIZE;
  187. pdmOut->dmFields &= ~DM_FORMNAME;
  188. pdmOut->dmPaperSize = pdmIn->dmPaperSize;
  189. CopyString(pdmOut->dmFormName, pdmIn->dmFormName, CCHFORMNAME);
  190. } else
  191. BadDevmode("paper size");
  192. } else if (pdmIn->dmFields & DM_FORMNAME) {
  193. pdmOut->dmFields |= DM_FORMNAME;
  194. pdmOut->dmFields &= ~DM_PAPERSIZE;
  195. CopyString(pdmOut->dmFormName, pdmIn->dmFormName, CCHFORMNAME);
  196. }
  197. //
  198. // Copies
  199. //
  200. if (pdmIn->dmFields & DM_COPIES) {
  201. if (pdmIn->dmCopies > 0)
  202. pdmOut->dmCopies = pdmIn->dmCopies;
  203. else
  204. BadDevmode("copy count");
  205. }
  206. //
  207. // Paper source
  208. //
  209. if (pdmIn->dmFields & DM_DEFAULTSOURCE) {
  210. if (pdmIn->dmDefaultSource == DMBIN_ONLYONE) {
  211. pdmOut->dmFields |= DM_DEFAULTSOURCE;
  212. pdmOut->dmDefaultSource = pdmIn->dmDefaultSource;
  213. } else
  214. BadDevmode("paper source");
  215. }
  216. //
  217. // Print quality
  218. //
  219. if ((pdmIn->dmFields & DM_PRINTQUALITY) &&
  220. (pdmIn->dmPrintQuality != FAXRES_HORIZONTAL))
  221. {
  222. BadDevmode("print quality");
  223. }
  224. if (pdmIn->dmFields & DM_YRESOLUTION)
  225. {
  226. if (pdmIn->dmYResolution <= FAXRES_VERTDRAFT)
  227. pdmOut->dmYResolution = FAXRES_VERTDRAFT;
  228. else
  229. pdmOut->dmYResolution = FAXRES_VERTICAL;
  230. }
  231. //
  232. // Private devmode fields
  233. //
  234. Assert(pdmDest->dmPrivate.signature == DRIVER_SIGNATURE);
  235. if (pdmPrivate->signature == DRIVER_SIGNATURE) {
  236. if (! publicOnly)
  237. memcpy(&pdmDest->dmPrivate, pdmPrivate, sizeof(DMPRIVATE));
  238. } else
  239. BadDevmode("bad signature");
  240. }
  241. pdmDest->dmPrivate.flags &= ~FAXDM_DRIVER_DEFAULT;
  242. MemFree(pdmAlloced);
  243. return valid;
  244. }