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.

530 lines
14 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. Module Name:
  4. formbox.c
  5. Abstract:
  6. This module contains functions to enumerate valid form and list on the
  7. combo box
  8. Author:
  9. 09-Dec-1993 Thu 14:31:44 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 DbgFormBox
  18. #define DBG_FORMS 0x00000001
  19. #define DBG_TRAY 0x00000002
  20. #define DBG_PERMISSION 0x00000004
  21. DEFINE_DBGVAR(0);
  22. WCHAR wszModel[] = L"Model";
  23. BOOL
  24. GetFormSelect(
  25. PPRINTERINFO pPI,
  26. POPTITEM pOptItem
  27. )
  28. /*++
  29. Routine Description:
  30. This function retrieve the form selected by the user from the combo
  31. box
  32. Arguments:
  33. pPI - Pointer to the PRINTERINFO
  34. pOptItem - Pointer to the FORM's OPTITEM
  35. Return Value:
  36. TRUE if sucessful and pPI will be set correctly, FALSE if error occurred
  37. Author:
  38. 09-Dec-1993 Thu 14:44:18 created
  39. 18-Dec-1993 Sat 03:55:30 updated
  40. Changed dmFields setting for the PAPER, now we will only set the
  41. DM_FORMNAME field, this way the returned document properties will be
  42. always in known form even user defines many forms in spooler.
  43. 06-Nov-1995 Mon 12:56:00 updated
  44. Re-write for the New UI
  45. Revision History:
  46. --*/
  47. {
  48. PAPERINFO CurPaper;
  49. POPTPARAM pOptParam;
  50. pOptParam = pOptItem->pOptType->pOptParam + pOptItem->Sel;
  51. if (pOptParam->Style == FS_ROLLPAPER) {
  52. PFORMSRC pFS;
  53. //
  54. // This was added from the GPC data for the roll feed
  55. //
  56. PLOTASSERT(0, "GetComboBoxSelForm: INTERNAL ERROR, ROLLPAPER In document properties",
  57. !(pPI->Flags & PIF_DOCPROP), 0);
  58. PLOTASSERT(0, "GetComboBoxSelForm: INTERNAL ERROR, device CANNOT have ROLLPAPER",
  59. pPI->pPlotGPC->Flags & PLOTF_ROLLFEED, 0);
  60. PLOTDBG(DBG_FORMS,
  61. ("Roll Feed Paper is selected, (%ld)", pOptParam->lParam));
  62. if (pOptParam->lParam < (LONG)pPI->pPlotGPC->Forms.Count) {
  63. pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData + pOptParam->lParam;
  64. //
  65. // Since the RollFeed paper has variable length, and the cy is set
  66. // to zero at GPC data, we must take that into account
  67. //
  68. CurPaper.Size = pFS->Size;
  69. CurPaper.ImageArea.left = pFS->Margin.left;
  70. CurPaper.ImageArea.top = pFS->Margin.top;
  71. CurPaper.ImageArea.right = CurPaper.Size.cx -
  72. pFS->Margin.right;
  73. CurPaper.ImageArea.bottom = pPI->pPlotGPC->DeviceSize.cy -
  74. pFS->Margin.bottom;
  75. str2Wstr(CurPaper.Name, CCHOF(CurPaper.Name), pFS->Name);
  76. } else {
  77. PLOTERR(("GetComboBoxSelForm: Internal Error, Invalid lParam=%ld",
  78. pOptParam->lParam));
  79. return(FALSE);
  80. }
  81. } else {
  82. FORM_INFO_1 *pFI1;
  83. DWORD cb;
  84. //
  85. // This form is in the form data base
  86. //
  87. pFI1 = pPI->pFI1Base + pOptParam->lParam;
  88. CurPaper.Size = pFI1->Size;
  89. CurPaper.ImageArea = pFI1->ImageableArea;
  90. WCPYFIELDNAME(CurPaper.Name, pFI1->pName);
  91. }
  92. //
  93. // Now we have current paper validated
  94. //
  95. if (pPI->Flags & PIF_DOCPROP) {
  96. //
  97. // Turn off first, then turn on paper fields as needed
  98. //
  99. pPI->PlotDM.dm.dmFields &= ~DM_PAPER_FIELDS;
  100. pPI->PlotDM.dm.dmFields |= (DM_FORMNAME | DM_PAPERSIZE);
  101. //
  102. // Copy down the dmFormName, dmPaperSize and set dmPaperWidth/Length,
  103. // the fields for PAPER will bb set to DM_FORMNAME so that we always
  104. // can find the form also we may set DM_PAPERSIZE if index number is
  105. // <= DMPAPER_LAST
  106. //
  107. WCPYFIELDNAME(pPI->PlotDM.dm.dmFormName, CurPaper.Name);
  108. pPI->PlotDM.dm.dmPaperSize = (SHORT)(pOptParam->lParam +
  109. DMPAPER_FIRST);
  110. pPI->PlotDM.dm.dmPaperWidth = SPLTODM(CurPaper.Size.cx);
  111. pPI->PlotDM.dm.dmPaperLength = SPLTODM(CurPaper.Size.cy);
  112. #if DBG
  113. *(PRECTL)&pPI->PlotDM.dm.dmBitsPerPel = CurPaper.ImageArea;
  114. #endif
  115. } else {
  116. pPI->CurPaper = CurPaper;
  117. }
  118. PLOTDBG(DBG_FORMS, ("*** GetComboBoxSelForm from COMBO = '%s'", CurPaper.Name));
  119. PLOTDBG(DBG_FORMS, ("Size=%ld x %ld", CurPaper.Size.cx, CurPaper.Size.cy));
  120. PLOTDBG(DBG_FORMS, ("ImageArea=(%ld, %ld) - (%ld, %ld)",
  121. CurPaper.ImageArea.left, CurPaper.ImageArea.top,
  122. CurPaper.ImageArea.right, CurPaper.ImageArea.bottom));
  123. return(TRUE);
  124. }
  125. UINT
  126. CreateFormOI(
  127. PPRINTERINFO pPI,
  128. POPTITEM pOptItem,
  129. POIDATA pOIData
  130. )
  131. /*++
  132. Routine Description:
  133. This function add the available forms to the combo box, it will optionally
  134. add the roll feed type of form
  135. Arguments:
  136. pPI - Pointer to the PRINTERINFO data structure
  137. pOptItem - Pointer to the FORM's OPTITEM
  138. pOIData - Pointer to the OIDATA structure
  139. Return Value:
  140. The form selected, a netavie number means error
  141. Author:
  142. 09-Dec-1993 Thu 14:35:59 created
  143. 06-Nov-1995 Mon 12:56:24 updated
  144. Re-write for the New UI
  145. Revision History:
  146. --*/
  147. {
  148. LPWSTR pwSelName;
  149. POPTPARAM pOptParam;
  150. PFORM_INFO_1 pFI1;
  151. PFORMSRC pFS;
  152. ENUMFORMPARAM EFP;
  153. DWORD i;
  154. LONG Sel;
  155. DWORD cRollPaper;
  156. EXTRAINFO EI;
  157. if (!pOptItem) {
  158. return(1);
  159. }
  160. pwSelName = (LPWSTR)((pPI->Flags & PIF_DOCPROP) ?
  161. pPI->PlotDM.dm.dmFormName : pPI->CurPaper.Name);
  162. PLOTDBG(DBG_FORMS, ("Current Form: <%ws>", pwSelName));
  163. EFP.pPlotDM = &(pPI->PlotDM);
  164. EFP.pPlotGPC = pPI->pPlotGPC;
  165. if (!PlotEnumForms(pPI->hPrinter, NULL, &EFP)) {
  166. PLOTERR(("CreateFormOI: PlotEnumForms() failed"));
  167. return(0);
  168. }
  169. cRollPaper = 0;
  170. if ((!(pPI->Flags & PIF_DOCPROP)) &&
  171. (pPI->pPlotGPC->Flags & PLOTF_ROLLFEED)) {
  172. //
  173. // Add device' roll paper to the combo box too.
  174. //
  175. PLOTDBG(DBG_FORMS, ("Device support ROLLFEED so add RollPaper if any"));
  176. for (i= 0, pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData;
  177. i < (DWORD)pPI->pPlotGPC->Forms.Count;
  178. i++, pFS++) {
  179. if (!pFS->Size.cy) {
  180. ++cRollPaper;
  181. }
  182. }
  183. }
  184. PLOTDBG(DBG_FORMS, ("Valid Count is %ld [%ld + %ld] out of %ld",
  185. EFP.ValidCount + cRollPaper,
  186. EFP.ValidCount, cRollPaper, EFP.Count));
  187. EI.Size = (DWORD)(cRollPaper * (sizeof(WCHAR) * CCHFORMNAME));
  188. if (!CreateOPTTYPE(pPI,
  189. pOptItem,
  190. pOIData,
  191. EFP.ValidCount + cRollPaper,
  192. &EI)) {
  193. LocalFree((HLOCAL)EFP.pFI1Base);
  194. return(0);
  195. }
  196. pPI->pFI1Base = EFP.pFI1Base;
  197. pOptItem->pOptType->Style = OTS_LBCB_SORT;
  198. pOptParam = pOptItem->pOptType->pOptParam;
  199. for (i = 0, Sel = 0, pFI1 = EFP.pFI1Base; i < EFP.Count; i++, pFI1++) {
  200. if (pFI1->Flags & FI1F_VALID_SIZE) {
  201. pOptParam->cbSize = sizeof(OPTPARAM);
  202. pOptParam->Style = (pPI->pPlotGPC->Flags & PLOTF_PAPERTRAY) ?
  203. FS_TRAYPAPER : 0;
  204. pOptParam->pData = pFI1->pName;
  205. pOptParam->IconID = (pFI1->Flags & FI1F_ENVELOPE) ?
  206. IDI_CPSUI_ENVELOPE : IDI_CPSUI_STD_FORM;
  207. pOptParam->lParam = (LONG)i;
  208. if (!lstrcmp(pwSelName, pOptParam->pData)) {
  209. pOptItem->Sel = Sel;
  210. }
  211. pOptParam++;
  212. Sel++;
  213. }
  214. }
  215. if (cRollPaper) {
  216. LPWSTR pwStr = (LPWSTR)EI.pData;
  217. size_t cchpwStr = EI.Size / sizeof(WCHAR);
  218. //
  219. // Add device' roll paper to the combo box too.
  220. //
  221. for (i = 0, pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData;
  222. i < (DWORD)pPI->pPlotGPC->Forms.Count;
  223. i++, pFS++) {
  224. if (!(pFS->Size.cy)) {
  225. //
  226. // Got one, we have to translated into the UNICODE first
  227. //
  228. pOptParam->cbSize = sizeof(OPTPARAM);
  229. pOptParam->Style = FS_ROLLPAPER;
  230. pOptParam->pData = (LPTSTR)pwStr;
  231. pwStr += CCHFORMNAME;
  232. cchpwStr -= CCHFORMNAME;
  233. pOptParam->IconID = IDI_ROLLPAPER;
  234. pOptParam->lParam = (LONG)i;
  235. str2Wstr(pOptParam->pData, cchpwStr, pFS->Name);
  236. if (!lstrcmp(pwSelName, pOptParam->pData)) {
  237. pOptItem->Sel = Sel;
  238. }
  239. pOptParam++;
  240. Sel++;
  241. }
  242. }
  243. }
  244. return(1);
  245. }
  246. BOOL
  247. AddFormsToDataBase(
  248. PPRINTERINFO pPI,
  249. BOOL DeleteFirst
  250. )
  251. /*++
  252. Routine Description:
  253. This function add driver supports forms to the data base
  254. Arguments:
  255. pPI - Pointer to the PRINTERINFO
  256. Return Value:
  257. BOOLEAN
  258. Author:
  259. 09-Dec-1993 Thu 22:38:27 created
  260. 27-Apr-1994 Wed 19:18:58 updated
  261. Fixed bug# 13592 which printman/spooler did not call ptrprop first but
  262. docprop so let us into unknown form database state,
  263. Revision History:
  264. --*/
  265. {
  266. WCHAR wName[CCHFORMNAME + 2];
  267. BOOL bRet;
  268. LONG i;
  269. DWORD Type;
  270. Type = REG_SZ;
  271. if ((GetPrinterData(pPI->hPrinter,
  272. wszModel,
  273. &Type,
  274. (LPBYTE)wName,
  275. sizeof(wName),
  276. &i) == ERROR_SUCCESS) &&
  277. (wcscmp(pPI->PlotDM.dm.dmDeviceName, wName))) {
  278. PLOTDBG(DBG_FORMS, ("Already added forms to the data base for %s",
  279. pPI->PlotDM.dm.dmDeviceName));
  280. return(TRUE);
  281. }
  282. //
  283. // Find out if we have permission to do this
  284. //
  285. if (SetPrinterData(pPI->hPrinter,
  286. wszModel,
  287. REG_SZ,
  288. (LPBYTE)pPI->PlotDM.dm.dmDeviceName,
  289. (wcslen(pPI->PlotDM.dm.dmDeviceName) + 1) *
  290. sizeof(WCHAR)) == ERROR_SUCCESS) {
  291. PFORMSRC pFS;
  292. FORM_INFO_1 FI1;
  293. //
  294. // We have permission to update the registry so do it now
  295. //
  296. pPI->Flags |= PIF_UPDATE_PERMISSION;
  297. PLOTDBG(DBG_PERMISSION,
  298. ("!!! MODEL NAME: '%s' not Match, Re-installed Form Database",
  299. pPI->PlotDM.dm.dmDeviceName));
  300. //
  301. // Add the driver supportes forms to the system spooler data base if
  302. // not yet done so
  303. //
  304. FI1.pName = wName;
  305. for (i = 0, pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData;
  306. i < (LONG)pPI->pPlotGPC->Forms.Count;
  307. i++, pFS++) {
  308. //
  309. // We will only add the non-roll paper forms
  310. //
  311. if (pFS->Size.cy) {
  312. str2Wstr(wName, CCHOF(wName), pFS->Name);
  313. //
  314. // Firstable we will delete the same name form in the data
  315. // base first, this will ensure we have our curent user defined
  316. // form can be installed
  317. //
  318. if (DeleteFirst) {
  319. DeleteForm(pPI->hPrinter, wName);
  320. }
  321. FI1.Size = pFS->Size;
  322. FI1.ImageableArea.left = pFS->Margin.left;
  323. FI1.ImageableArea.top = pFS->Margin.top;
  324. FI1.ImageableArea.right = FI1.Size.cx - pFS->Margin.right;
  325. FI1.ImageableArea.bottom = FI1.Size.cy - pFS->Margin.bottom;
  326. PLOTDBG(DBG_FORMS, (
  327. "AddForm: %s-[%ld x %ld] (%ld, %ld)-(%ld, %ld)",
  328. FI1.pName, FI1.Size.cx, FI1.Size.cy,
  329. FI1.ImageableArea.left, FI1.ImageableArea.top,
  330. FI1.ImageableArea.right,FI1.ImageableArea.bottom));
  331. FI1.Flags = FORM_PRINTER;
  332. if ((!AddForm(pPI->hPrinter, 1, (LPBYTE)&FI1)) &&
  333. (GetLastError() != ERROR_FILE_EXISTS) &&
  334. (GetLastError() != ERROR_ALREADY_EXISTS)) {
  335. bRet = FALSE;
  336. PLOTERR(("AddFormsToDataBase: AddForm(%s) failed, [%ld]",
  337. wName, GetLastError()));
  338. }
  339. }
  340. }
  341. return(TRUE);
  342. } else {
  343. pPI->Flags &= ~PIF_UPDATE_PERMISSION;
  344. PLOTDBG(DBG_PERMISSION, ("AddFormsToDataBase(): NO UPDATE PERMISSION"));
  345. return(FALSE);
  346. }
  347. }