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.

481 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. Module Name:
  4. ptrInfo.c
  5. Abstract:
  6. This module contains functions to mappring a hPrinter to useful data, it
  7. will also cached the printerinfo data
  8. Author:
  9. 03-Dec-1993 Fri 00:16:37 created
  10. [Environment:]
  11. GDI Device Driver - Plotter.
  12. [Notes:]
  13. Revision History:
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. #define DBG_PLOTFILENAME DbgPtrInfo
  18. #define DBG_MAPPRINTER 0x00000001
  19. #define DBG_CACHE_DATA 0x00000002
  20. DEFINE_DBGVAR(0);
  21. PPRINTERINFO
  22. MapPrinter(
  23. HANDLE hPrinter,
  24. PPLOTDEVMODE pPlotDMIn,
  25. LPDWORD pdwErrIDS,
  26. DWORD MPFlags
  27. )
  28. /*++
  29. Routine Description:
  30. This function map a handle to the printer to useful information for the
  31. plotter UI
  32. Arguments:
  33. hPrinter - Handle to the printer
  34. pPlotDMIn - pointer to the PLOTDEVMODE pass in to be validate and merge
  35. with default into pPI->PlotDM, if this pointer is NULL then
  36. a default PLOTDEVMODE is set in the pPI
  37. pdwErrIDS - pointer to a DWORD to store the error string ID if an error
  38. occured.
  39. MPFlags - MPF_xxxx flags for this function
  40. Return Value:
  41. return a pointer to the PRINTERINFO data structure, if NULL then it failed
  42. when a pPI is returned then following fields are set and validated
  43. hPrinter, pPlotGPC, CurPaper.
  44. and following fields are set to NULL
  45. Flags,
  46. Author:
  47. 02-Dec-1993 Thu 23:04:18 created
  48. 29-Dec-1993 Wed 14:50:23 updated
  49. NOT automatically select AUTO_ROTATE if roll feed device
  50. Revision History:
  51. --*/
  52. {
  53. HANDLE hHeap;
  54. PPRINTERINFO pPI;
  55. PPLOTGPC pPlotGPC;
  56. WCHAR DeviceName[CCHDEVICENAME];
  57. UINT cPenSet;
  58. UINT MaxPens;
  59. DWORD cbPen;
  60. DWORD cb;
  61. if (!(pPlotGPC = hPrinterToPlotGPC(hPrinter, DeviceName, CCHOF(DeviceName)))) {
  62. if (pdwErrIDS) {
  63. *pdwErrIDS = IDS_NO_MEMORY;
  64. }
  65. return(NULL);
  66. }
  67. cPenSet = 0;
  68. if (pPlotGPC->Flags & PLOTF_RASTER) {
  69. cb = sizeof(PRINTERINFO) +
  70. ((MPFlags & MPF_DEVICEDATA) ?
  71. (sizeof(DEVHTADJDATA) + (sizeof(DEVHTINFO) * 2)) : 0);
  72. } else {
  73. MaxPens = (UINT)pPlotGPC->MaxPens;
  74. cbPen = (DWORD)(sizeof(PENDATA) * MaxPens);
  75. cPenSet = (MPFlags & MPF_DEVICEDATA) ? PRK_MAX_PENDATA_SET : 1;
  76. cb = sizeof(PRINTERINFO) + (DWORD)(cbPen * cPenSet);
  77. }
  78. if (!(pPI = (PPRINTERINFO)LocalAlloc(LPTR,
  79. cb + ((MPFlags & MPF_PCPSUI) ?
  80. sizeof(COMPROPSHEETUI) : 0)))) {
  81. UnGetCachedPlotGPC(pPlotGPC);
  82. if (pdwErrIDS) {
  83. *pdwErrIDS = IDS_NO_MEMORY;
  84. }
  85. return(NULL);
  86. }
  87. if (MPFlags & MPF_PCPSUI) {
  88. pPI->pCPSUI = (PCOMPROPSHEETUI)((LPBYTE)pPI + cb);
  89. }
  90. pPI->hPrinter = hPrinter;
  91. pPI->pPlotDMIn = pPlotDMIn;
  92. pPI->PPData.Flags = PPF_AUTO_ROTATE |
  93. PPF_SMALLER_FORM |
  94. PPF_MANUAL_FEED_CX;
  95. pPI->IdxPenSet = 0;
  96. pPI->pPlotGPC = pPlotGPC;
  97. pPI->dmErrBits = ValidateSetPLOTDM(hPrinter,
  98. pPlotGPC,
  99. DeviceName,
  100. pPlotDMIn,
  101. &(pPI->PlotDM),
  102. NULL);
  103. GetDefaultPlotterForm(pPlotGPC, &(pPI->CurPaper));
  104. if (pPlotGPC->Flags & PLOTF_RASTER) {
  105. //
  106. // Get the raster plotter default and settings
  107. //
  108. if (MPFlags & MPF_DEVICEDATA) {
  109. PDEVHTADJDATA pDHTAD;
  110. PDEVHTINFO pDefHTInfo;
  111. PDEVHTINFO pAdjHTInfo;
  112. pAdjHTInfo = PI_PADJHTINFO(pPI);
  113. pDHTAD = PI_PDEVHTADJDATA(pPI);
  114. pDefHTInfo = (PDEVHTINFO)(pDHTAD + 1);
  115. pDHTAD->DeviceFlags = (pPlotGPC->Flags & PLOTF_COLOR) ?
  116. DEVHTADJF_COLOR_DEVICE : 0;
  117. pDHTAD->DeviceXDPI = (DWORD)pPI->pPlotGPC->RasterXDPI;
  118. pDHTAD->DeviceYDPI = (DWORD)pPI->pPlotGPC->RasterYDPI;
  119. pDHTAD->pDefHTInfo = pDefHTInfo;
  120. pDHTAD->pAdjHTInfo = pAdjHTInfo;
  121. pDefHTInfo->HTFlags = HT_FLAG_HAS_BLACK_DYE;
  122. pDefHTInfo->HTPatternSize = (DWORD)pPlotGPC->HTPatternSize;
  123. pDefHTInfo->DevPelsDPI = (DWORD)pPlotGPC->DevicePelsDPI;
  124. pDefHTInfo->ColorInfo = pPlotGPC->ci;
  125. *pAdjHTInfo = *pDefHTInfo;
  126. UpdateFromRegistry(hPrinter,
  127. &(pAdjHTInfo->ColorInfo),
  128. &(pAdjHTInfo->DevPelsDPI),
  129. &(pAdjHTInfo->HTPatternSize),
  130. &(pPI->CurPaper),
  131. &(pPI->PPData),
  132. NULL,
  133. 0,
  134. NULL);
  135. }
  136. } else {
  137. PPENDATA pPenData;
  138. WORD IdxPenSet;
  139. //
  140. // Get the pen plotter default and settings
  141. //
  142. pPenData = PI_PPENDATA(pPI);
  143. UpdateFromRegistry(hPrinter,
  144. NULL,
  145. NULL,
  146. NULL,
  147. &(pPI->CurPaper),
  148. &(pPI->PPData),
  149. &(pPI->IdxPenSet),
  150. 0,
  151. NULL);
  152. if (MPFlags & MPF_DEVICEDATA) {
  153. IdxPenSet = 0;
  154. } else {
  155. IdxPenSet = (WORD)pPI->IdxPenSet;
  156. }
  157. //
  158. // Set default pen set and get all the pen set back
  159. //
  160. while (cPenSet--) {
  161. CopyMemory(pPenData, pPlotGPC->Pens.pData, cbPen);
  162. UpdateFromRegistry(hPrinter,
  163. NULL,
  164. NULL,
  165. NULL,
  166. NULL,
  167. NULL,
  168. NULL,
  169. MAKELONG(IdxPenSet, MaxPens),
  170. pPenData);
  171. IdxPenSet++;
  172. (LPBYTE)pPenData += cbPen;
  173. }
  174. }
  175. if (MPFlags & MPF_HELPFILE) {
  176. GetPlotHelpFile(pPI);
  177. }
  178. return(pPI);
  179. }
  180. VOID
  181. UnMapPrinter(
  182. PPRINTERINFO pPI
  183. )
  184. /*++
  185. Routine Description:
  186. Arguments:
  187. Return Value:
  188. Author:
  189. 01-Nov-1995 Wed 19:05:40 created
  190. Revision History:
  191. --*/
  192. {
  193. if (pPI) {
  194. if (pPI->pPlotGPC) {
  195. UnGetCachedPlotGPC(pPI->pPlotGPC);
  196. }
  197. if (pPI->pFI1Base) {
  198. LocalFree((HLOCAL)pPI->pFI1Base);
  199. }
  200. if (pPI->pHelpFile) {
  201. LocalFree((HLOCAL)pPI->pHelpFile);
  202. }
  203. if (pPI->pOptItem) {
  204. POPTITEM pOI = pPI->pOptItem;
  205. UINT cOI = (UINT)pPI->cOptItem;
  206. while (cOI--) {
  207. if (pOI->UserData) {
  208. LocalFree((HLOCAL)pOI->UserData);
  209. }
  210. pOI++;
  211. }
  212. LocalFree((HLOCAL)pPI->pOptItem);
  213. }
  214. LocalFree((HLOCAL)pPI);
  215. }
  216. }
  217. LPBYTE
  218. GetPrinterInfo(
  219. HANDLE hPrinter,
  220. UINT PrinterInfoLevel
  221. )
  222. /*++
  223. Routine Description:
  224. This function get the DRIVER_INFO_1 Pointer from a hPrinter
  225. Arguments:
  226. hPrinter - The handle to the printer interested
  227. PrinterInfoLevel - It can be PRINTER_INFO_1, PRINTER_INFO_2,
  228. PRINTER_INFO_3, PRINTER_4, PRINTER_INFO_5.
  229. Return Value:
  230. the return value is NULL if failed else a pointer to the PRINTER_INFO_X
  231. where X is from 1 to 5. the caller must call LocalFree() to free the
  232. memory object after using it.
  233. Author:
  234. 16-Nov-1995 Thu 23:58:37 created
  235. Revision History:
  236. --*/
  237. {
  238. LPVOID pb;
  239. DWORD cb;
  240. //
  241. // Find out total bytes required
  242. //
  243. GetPrinter(hPrinter, PrinterInfoLevel, NULL, 0, &cb);
  244. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
  245. PLOTERR(("GetPrinterInfo%d: GetPrinterPrinter(1st) error=%08lx",
  246. PrinterInfoLevel, xGetLastError()));
  247. } else if (!(pb = (LPBYTE)LocalAlloc(LMEM_FIXED, cb))) {
  248. PLOTERR(("GetPrinterInfo%d: LocalAlloc(%ld) failed", PrinterInfoLevel, cb));
  249. } else if (GetPrinter(hPrinter, PrinterInfoLevel, pb, cb, &cb)) {
  250. //
  251. // Got it allright, so return it
  252. //
  253. return(pb);
  254. } else {
  255. PLOTERR(("GetPrinterInfo%d: GetPrinterPrinter(2nd) error=%08lx",
  256. PrinterInfoLevel, xGetLastError()));
  257. LocalFree((HLOCAL)pb);
  258. }
  259. return(NULL);
  260. }
  261. DWORD
  262. GetPlotterIconID(
  263. PPRINTERINFO pPI
  264. )
  265. /*++
  266. Routine Description:
  267. Arguments:
  268. Return Value:
  269. Author:
  270. 29-Nov-1995 Wed 19:32:00 created
  271. Revision History:
  272. --*/
  273. {
  274. DWORD Flags;
  275. DWORD IconID;
  276. if ((Flags = pPI->pPlotGPC->Flags) & PLOTF_RASTER) {
  277. IconID = (Flags & PLOTF_ROLLFEED) ? IDI_RASTER_ROLLFEED :
  278. IDI_RASTER_TRAYFEED;
  279. } else {
  280. IconID = (Flags & PLOTF_ROLLFEED) ? IDI_PEN_ROLLFEED :
  281. IDI_PEN_TRAYFEED;
  282. }
  283. return(IconID);
  284. }