Leaked source code of windows server 2003
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.

341 lines
8.4 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. short DefualtPaperSize = DMPAPER_LETTER; // Letter
  38. LPTSTR lptstrDefualtPaperName = FORMNAME_LETTER;
  39. //
  40. // Default value for public devmode fields
  41. //
  42. memset(pdm, 0, sizeof(DRVDEVMODE));
  43. if (pDeviceName == NULL)
  44. pDeviceName = DRIVER_NAME;
  45. CopyString(pdm->dmPublic.dmDeviceName, pDeviceName, CCHDEVICENAME);
  46. pdm->dmPublic.dmDriverVersion = DRIVER_VERSION;
  47. pdm->dmPublic.dmSpecVersion = DM_SPECVERSION;
  48. pdm->dmPublic.dmSize = sizeof(DEVMODE);
  49. pdm->dmPublic.dmDriverExtra = sizeof(DMPRIVATE);
  50. pdm->dmPublic.dmFields = DM_ORIENTATION |
  51. DM_PAPERSIZE |
  52. DM_FORMNAME |
  53. DM_PRINTQUALITY |
  54. DM_YRESOLUTION |
  55. DM_DEFAULTSOURCE;
  56. pdm->dmPublic.dmOrientation = DMORIENT_PORTRAIT;
  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.dmTTOption = DMTT_BITMAP;
  62. pdm->dmPublic.dmColor = DMCOLOR_MONOCHROME;
  63. pdm->dmPublic.dmDefaultSource = DMBIN_ONLYONE;
  64. if (hPrinter)
  65. {
  66. switch (GetPrinterDataDWord(hPrinter, PRNDATA_PAPER_SIZE, DMPAPER_LETTER))
  67. {
  68. case DMPAPER_A4:
  69. DefualtPaperSize = DMPAPER_A4;
  70. lptstrDefualtPaperName = FORMNAME_A4;
  71. break;
  72. case DMPAPER_LEGAL:
  73. DefualtPaperSize = DMPAPER_LEGAL;
  74. lptstrDefualtPaperName = FORMNAME_LEGAL;
  75. break;
  76. }
  77. }
  78. pdm->dmPublic.dmPaperSize = DefualtPaperSize;
  79. CopyString(pdm->dmPublic.dmFormName, lptstrDefualtPaperName, CCHFORMNAME);
  80. //
  81. // Private devmode fields
  82. //
  83. #ifdef KERNEL_MODE
  84. pdm->dmPrivate.signature = DRIVER_SIGNATURE;
  85. pdm->dmPrivate.flags = 0;
  86. pdm->dmPrivate.sendCoverPage = TRUE;
  87. pdm->dmPrivate.whenToSend = JSA_NOW;
  88. #else
  89. dmSource = (PDRVDEVMODE) GetPerUserDevmode(pDeviceName);
  90. if (!dmSource) {
  91. //
  92. // default values
  93. //
  94. pdm->dmPrivate.signature = DRIVER_SIGNATURE;
  95. pdm->dmPrivate.flags = 0;
  96. pdm->dmPrivate.sendCoverPage = TRUE;
  97. pdm->dmPrivate.whenToSend = JSA_NOW;
  98. } else {
  99. dmPrivate = &dmSource->dmPrivate;
  100. pdm->dmPrivate.signature = dmPrivate->signature;//DRIVER_SIGNATURE;
  101. pdm->dmPrivate.flags = dmPrivate->flags;// 0;
  102. pdm->dmPrivate.sendCoverPage = dmPrivate->sendCoverPage; //TRUE;
  103. pdm->dmPrivate.whenToSend = dmPrivate->whenToSend;//JSA_NOW;
  104. pdm->dmPrivate.sendAtTime = dmPrivate->sendAtTime;
  105. CopyString(pdm->dmPrivate.billingCode,dmPrivate->billingCode,MAX_USERINFO_BILLING_CODE + 1);
  106. CopyString(pdm->dmPrivate.emailAddress,dmPrivate->emailAddress,MAX_EMAIL_ADDRESS);
  107. MemFree(dmSource);
  108. }
  109. #endif
  110. }
  111. BOOL
  112. MergeDevmode(
  113. PDRVDEVMODE pdmDest,
  114. PDEVMODE pdmSrc,
  115. BOOL publicOnly
  116. )
  117. /*++
  118. Routine Description:
  119. Merge the source devmode into the destination devmode
  120. Arguments:
  121. pdmDest - Specifies the destination devmode
  122. pdmSrc - Specifies the source devmode
  123. publicOnly - Only merge public portion of the devmode
  124. Return Value:
  125. TRUE if successful, FALSE if the source devmode is invalid
  126. [Note:]
  127. pdmDest must point to a valid current-version devmode
  128. --*/
  129. #define BadDevmode(reason) { Error(("Invalid DEVMODE: %s\n", reason)); valid = FALSE; }
  130. {
  131. PDEVMODE pdmIn, pdmOut, pdmAlloced = NULL;
  132. PDMPRIVATE pdmPrivate;
  133. BOOL valid = TRUE;
  134. //
  135. // If there is no source devmode, levae destination devmode untouched
  136. //
  137. if ((pdmIn = pdmSrc) == NULL)
  138. return TRUE;
  139. //
  140. // Convert source devmode to current version if necessary
  141. //
  142. if (! CurrentVersionDevmode(pdmIn)) {
  143. Warning(("Converting non-current version DEVMODE ...\n"));
  144. if (! (pdmIn = pdmAlloced = MemAlloc(sizeof(DRVDEVMODE)))) {
  145. Error(("Memory allocation failed\n"));
  146. return FALSE;
  147. }
  148. Assert(pdmDest->dmPublic.dmSize == sizeof(DEVMODE) &&
  149. pdmDest->dmPublic.dmDriverExtra == sizeof(DMPRIVATE));
  150. memcpy(pdmIn, pdmDest, sizeof(DRVDEVMODE));
  151. if (ConvertDevmode(pdmSrc, pdmIn) <= 0) {
  152. Error(("ConvertDevmode failed\n"));
  153. MemFree(pdmAlloced);
  154. return FALSE;
  155. }
  156. }
  157. //
  158. // If the input devmode is the same as the driver default,
  159. // there is no need to merge it.
  160. //
  161. pdmPrivate = &((PDRVDEVMODE) pdmIn)->dmPrivate;
  162. if (pdmPrivate->signature == DRIVER_SIGNATURE &&
  163. (pdmPrivate->flags & FAXDM_DRIVER_DEFAULT))
  164. {
  165. Verbose(("Merging driver default devmode.\n"));
  166. }
  167. else
  168. {
  169. //
  170. // Merge source devmode into destination devmode
  171. //
  172. pdmOut = &pdmDest->dmPublic;
  173. //
  174. // Device name: Always the same as printer name
  175. //
  176. // CopyString(pdmOut->dmDeviceName, pdmIn->dmDeviceName, CCHDEVICENAME);
  177. //
  178. // Orientation
  179. //
  180. if (pdmIn->dmFields & DM_ORIENTATION) {
  181. if (pdmIn->dmOrientation == DMORIENT_PORTRAIT ||
  182. pdmIn->dmOrientation == DMORIENT_LANDSCAPE)
  183. {
  184. pdmOut->dmFields |= DM_ORIENTATION;
  185. pdmOut->dmOrientation = pdmIn->dmOrientation;
  186. } else
  187. BadDevmode("orientation");
  188. }
  189. //
  190. // Form selection
  191. //
  192. if (pdmIn->dmFields & DM_PAPERSIZE) {
  193. if (pdmIn->dmPaperSize >= DMPAPER_FIRST) {
  194. pdmOut->dmFields |= DM_PAPERSIZE;
  195. pdmOut->dmFields &= ~DM_FORMNAME;
  196. pdmOut->dmPaperSize = pdmIn->dmPaperSize;
  197. CopyString(pdmOut->dmFormName, pdmIn->dmFormName, CCHFORMNAME);
  198. } else
  199. BadDevmode("paper size");
  200. } else if (pdmIn->dmFields & DM_FORMNAME) {
  201. pdmOut->dmFields |= DM_FORMNAME;
  202. pdmOut->dmFields &= ~DM_PAPERSIZE;
  203. CopyString(pdmOut->dmFormName, pdmIn->dmFormName, CCHFORMNAME);
  204. }
  205. //
  206. // Paper source
  207. //
  208. if (pdmIn->dmFields & DM_DEFAULTSOURCE) {
  209. if (pdmIn->dmDefaultSource == DMBIN_ONLYONE) {
  210. pdmOut->dmFields |= DM_DEFAULTSOURCE;
  211. pdmOut->dmDefaultSource = pdmIn->dmDefaultSource;
  212. } else
  213. BadDevmode("paper source");
  214. }
  215. //
  216. // Print quality
  217. //
  218. if ((pdmIn->dmFields & DM_PRINTQUALITY) &&
  219. (pdmIn->dmPrintQuality != FAXRES_HORIZONTAL))
  220. {
  221. BadDevmode("print quality");
  222. }
  223. if (pdmIn->dmFields & DM_YRESOLUTION)
  224. {
  225. if (pdmIn->dmYResolution <= FAXRES_VERTDRAFT)
  226. pdmOut->dmYResolution = FAXRES_VERTDRAFT;
  227. else
  228. pdmOut->dmYResolution = FAXRES_VERTICAL;
  229. }
  230. //
  231. // Private devmode fields
  232. //
  233. Assert(pdmDest->dmPrivate.signature == DRIVER_SIGNATURE);
  234. if (pdmPrivate->signature == DRIVER_SIGNATURE) {
  235. if (! publicOnly)
  236. memcpy(&pdmDest->dmPrivate, pdmPrivate, sizeof(DMPRIVATE));
  237. } else
  238. BadDevmode("bad signature");
  239. }
  240. pdmDest->dmPrivate.flags &= ~FAXDM_DRIVER_DEFAULT;
  241. MemFree(pdmAlloced);
  242. return valid;
  243. }