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.

427 lines
12 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1990 Microsoft Corporation */
  3. /************************************************************/
  4. /* This file contains the dialog box routines for the print dialog box and the
  5. printer initialization code. */
  6. #define NOGDICAPMASKS
  7. #define NOVIRTUALKEYCODES
  8. #define NOWINSTYLES
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #define NOCLIPBOARD
  12. #define NOKEYSTATE
  13. #define NOSYSCOMMANDS
  14. #define NORASTEROPS
  15. #define NOSHOWWINDOW
  16. #define NOATOM
  17. #define NOCREATESTRUCT
  18. #define NODRAWTEXT
  19. #define NOMB
  20. #define NOMEMMGR
  21. #define NOMETAFILE
  22. #define NOWH
  23. #define NOWNDCLASS
  24. #define NOSOUND
  25. #define NOCOLOR
  26. #define NOSCROLL
  27. #define NOCOMM
  28. #include <windows.h>
  29. #include "mw.h"
  30. #include "cmddefs.h"
  31. #include "dlgdefs.h"
  32. #include "str.h"
  33. #include "printdef.h"
  34. #include "fmtdefs.h"
  35. #include "propdefs.h"
  36. fnPrPrinter()
  37. {
  38. /* This routine is the outside world's interface to the print code. */
  39. extern HWND hParentWw;
  40. extern HANDLE hMmwModInstance;
  41. extern CHAR *vpDlgBuf;
  42. extern int docCur;
  43. CHAR rgbDlgBuf[sizeof(int) + 2 * sizeof(BOOL)];
  44. #ifdef INEFFLOCKDOWN
  45. extern FARPROC lpDialogPrint;
  46. #else
  47. BOOL far PASCAL DialogPrint(HWND, unsigned, WORD, LONG);
  48. FARPROC lpDialogPrint;
  49. if (!(lpDialogPrint = MakeProcInstance(DialogPrint, hMmwModInstance)))
  50. {
  51. WinFailure();
  52. return;
  53. }
  54. #endif
  55. vpDlgBuf = &rgbDlgBuf[0];
  56. switch (OurDialogBox(hMmwModInstance, MAKEINTRESOURCE(dlgPrint), hParentWw,
  57. lpDialogPrint))
  58. {
  59. case idiOk:
  60. /* Force all of the windows to clean up their act. */
  61. DispatchPaintMsg();
  62. /* At this point, we have the following :
  63. vfPrPages = true if print page range else print all pages
  64. vpgnBegin = starting page number (if vfPrPages)
  65. vpgnEnd = ending page number (if vfPrPages)
  66. vcCopies = number of copies to print */
  67. PrintDoc(docCur, TRUE);
  68. break;
  69. case -1:
  70. /* We didn't even have enough memory to create the dialog box. */
  71. #ifdef WIN30
  72. WinFailure();
  73. #else
  74. Error(IDPMTNoMemory);
  75. #endif
  76. break;
  77. }
  78. #ifndef INEFFLOCKDOWN
  79. FreeProcInstance(lpDialogPrint);
  80. #endif
  81. }
  82. BOOL far PASCAL DialogPrint( hDlg, message, wParam, lParam )
  83. HWND hDlg;
  84. unsigned message;
  85. WORD wParam;
  86. LONG lParam;
  87. {
  88. /* This routine handles input to the Print dialog box. */
  89. extern CHAR *vpDlgBuf;
  90. extern int vfPrPages; /* true if print page range */
  91. extern int vpgnBegin; /* starting page number to print */
  92. extern int vpgnEnd; /* ending page number to print */
  93. extern int vcCopies; /* nubmer of copies to print */
  94. extern BOOL vfPrinterValid;
  95. extern HDC vhDCPrinter;
  96. extern int vfDraftMode;
  97. extern HWND vhWndMsgBoxParent;
  98. extern ferror;
  99. extern HCURSOR vhcArrow;
  100. extern int vfCursorVisible;
  101. extern CHAR (**hszPrinter)[];
  102. extern CHAR (**hszPrDriver)[];
  103. extern CHAR (**hszPrPort)[];
  104. int *pidiRBDown = (int *)vpDlgBuf;
  105. BOOL *pfDraftMode = (BOOL *)(vpDlgBuf + sizeof(int));
  106. BOOL *pfDraftSupport = (BOOL *)(vpDlgBuf + sizeof(int) + sizeof(BOOL));
  107. int iEscape;
  108. CHAR szPrDescrip[cchMaxProfileSz];
  109. switch (message)
  110. {
  111. case WM_INITDIALOG:
  112. BuildPrSetupSz(szPrDescrip, &(**hszPrinter)[0], &(**hszPrPort)[0]);
  113. SetDlgItemText(hDlg, idiPrtDest, (LPSTR)szPrDescrip);
  114. SetDlgItemText(hDlg, idiPrtCopies, (LPSTR)"1");
  115. SelectIdiText(hDlg, idiPrtCopies);
  116. if (vfPrPages)
  117. {
  118. *pidiRBDown = idiPrtFrom;
  119. SetDlgItemInt(hDlg, idiPrtPageFrom, vpgnBegin, TRUE);
  120. SetDlgItemInt(hDlg, idiPrtPageTo, vpgnEnd, TRUE);
  121. }
  122. else
  123. {
  124. *pidiRBDown = idiPrtAll;
  125. }
  126. iEscape = DRAFTMODE;
  127. if (*pfDraftSupport = vfPrinterValid && vhDCPrinter &&
  128. Escape(vhDCPrinter, QUERYESCSUPPORT, sizeof(int),
  129. (LPSTR)&iEscape, (LPSTR)NULL))
  130. {
  131. CheckDlgButton(hDlg, idiPrtDraft, *pfDraftMode = vfDraftMode);
  132. }
  133. else
  134. {
  135. EnableWindow(GetDlgItem(hDlg, idiPrtDraft), FALSE);
  136. if (!vhDCPrinter) /* we've got a timing thing whereby they
  137. managed to get into the print dialog
  138. inbetween the time printer.setup had
  139. unhooked the old printer and the hookup
  140. of the new one! ..pault */
  141. EnableWindow(GetDlgItem(hDlg, idiOk), FALSE);
  142. }
  143. CheckDlgButton(hDlg, *pidiRBDown, TRUE);
  144. EnableOtherModeless(FALSE);
  145. break;
  146. case WM_SETVISIBLE:
  147. if (wParam)
  148. {
  149. EndLongOp(vhcArrow);
  150. }
  151. return(FALSE);
  152. case WM_ACTIVATE:
  153. if (wParam)
  154. {
  155. vhWndMsgBoxParent = hDlg;
  156. }
  157. if (vfCursorVisible)
  158. {
  159. ShowCursor(wParam);
  160. }
  161. return (FALSE);
  162. case WM_COMMAND:
  163. switch (wParam)
  164. {
  165. BOOL fPages;
  166. int pgnBegin;
  167. int pgnEnd;
  168. int cCopies;
  169. case idiOk:
  170. if (fPages = (*pidiRBDown == idiPrtFrom))
  171. {
  172. /* Get the range of pages to print. */
  173. if (!WPwFromItW3Id(&pgnBegin, hDlg, idiPrtPageFrom,
  174. pgnMin, pgnMax, wNormal, IDPMTNPI))
  175. {
  176. /* Reset error condition, so as to report any further error.
  177. */
  178. ferror = FALSE;
  179. return(TRUE);
  180. }
  181. if (!WPwFromItW3Id(&pgnEnd, hDlg, idiPrtPageTo,
  182. pgnMin, pgnMax, wNormal, IDPMTNPI))
  183. {
  184. /* Reset error condition, so as to report any further error.
  185. */
  186. ferror = FALSE;
  187. return(TRUE);
  188. }
  189. }
  190. /* Get the number of copies to print. */
  191. if (!WPwFromItW3IdFUt(&cCopies, hDlg, idiPrtCopies, 1, 32767,
  192. wNormal, IDPMTNPI, FALSE, 0
  193. ))
  194. {
  195. /* Reset error condition, so as to report any further error. */
  196. ferror = FALSE;
  197. return(TRUE);
  198. }
  199. /* If we have gotten this far, then everything must be okey-dokey.
  200. */
  201. vfDraftMode = *pfDraftSupport ? *pfDraftMode : FALSE;
  202. if (vfPrPages = fPages)
  203. {
  204. vpgnBegin = pgnBegin;
  205. vpgnEnd = pgnEnd;
  206. }
  207. vcCopies = cCopies;
  208. case idiCancel:
  209. OurEndDialog(hDlg, wParam);
  210. break;
  211. case idiPrtPageFrom:
  212. case idiPrtPageTo:
  213. if (HIWORD(lParam) == EN_CHANGE)
  214. {
  215. if (SendMessage(LOWORD(lParam), WM_GETTEXTLENGTH, 0, 0L) &&
  216. *pidiRBDown != idiPrtFrom)
  217. {
  218. CheckDlgButton(hDlg, *pidiRBDown, FALSE);
  219. CheckDlgButton(hDlg, *pidiRBDown = idiPrtFrom, TRUE);
  220. }
  221. return(TRUE);
  222. }
  223. return(FALSE);
  224. case idiPrtAll:
  225. case idiPrtFrom:
  226. CheckDlgButton(hDlg, *pidiRBDown, FALSE);
  227. CheckDlgButton(hDlg, *pidiRBDown = wParam, TRUE);
  228. // set focus to the edit field automatically
  229. if (wParam == idiPrtFrom)
  230. SetFocus(GetDlgItem(hDlg, idiPrtPageFrom));
  231. break;
  232. case idiPrtDraft:
  233. CheckDlgButton(hDlg, wParam, *pfDraftMode = !(*pfDraftMode));
  234. break;
  235. default:
  236. return(FALSE);
  237. }
  238. break;
  239. default:
  240. return(FALSE);
  241. }
  242. return(TRUE);
  243. }
  244. BOOL FInitHeaderFooter(fHeader, ppgn, phrgpld, pcpld)
  245. BOOL fHeader;
  246. unsigned *ppgn;
  247. struct PLD (***phrgpld)[];
  248. int *pcpld;
  249. {
  250. /* This routine initializes the array of print line descriptors used in
  251. positioning the header/footer on the printed page. FALSE is returned if an
  252. error occurs; TRUE otherwise. */
  253. extern typeCP cpMinHeader;
  254. extern typeCP cpMacHeader;
  255. extern typeCP cpMinFooter;
  256. extern typeCP cpMacFooter;
  257. extern int docCur;
  258. extern struct PAP vpapAbs;
  259. extern struct SEP vsepAbs;
  260. extern int dxaPrOffset;
  261. extern int dyaPrOffset;
  262. extern int dxpPrPage;
  263. extern int dxaPrPage;
  264. extern int dypPrPage;
  265. extern int dyaPrPage;
  266. extern struct FLI vfli;
  267. extern int vfOutOfMemory;
  268. typeCP cpMin;
  269. typeCP cpMac;
  270. /* Get the cpMin and the cpMac for the header/footer. */
  271. if (fHeader)
  272. {
  273. cpMin = cpMinHeader;
  274. cpMac = cpMacHeader;
  275. }
  276. else
  277. {
  278. cpMin = cpMinFooter;
  279. cpMac = cpMacFooter;
  280. }
  281. /* Is there a header/footer. */
  282. if (cpMac - cpMin > ccpEol)
  283. {
  284. int cpld = 0;
  285. int cpldReal = 0;
  286. int cpldMax;
  287. int xp;
  288. int yp;
  289. int ichCp = 0;
  290. typeCP cpMacDoc = CpMacText(docCur);
  291. /* Compute the page number of the start of the headers/footers. */
  292. CacheSect(docCur, cpMin);
  293. if ((*ppgn = vsepAbs.pgnStart) == pgnNil)
  294. {
  295. *ppgn = 1;
  296. }
  297. /* Does the header/footer appear on the first page. */
  298. CachePara(docCur, cpMin);
  299. if (!(vpapAbs.rhc & RHC_fFirst))
  300. {
  301. (*ppgn)++;
  302. }
  303. /* Calculate the bounds of the header/footer in pixels. */
  304. xp = MultDiv(vsepAbs.xaLeft - dxaPrOffset, dxpPrPage, dxaPrPage);
  305. yp = fHeader ? MultDiv(vsepAbs.yaRH1 - dyaPrOffset, dypPrPage,
  306. dyaPrPage) : 0;
  307. /* Initialize the array of print line descriptors for the header/footer.
  308. */
  309. if (FNoHeap(*phrgpld = (struct PLD (**)[])HAllocate((cpldMax = cpldRH) *
  310. cwPLD)))
  311. {
  312. *phrgpld = NULL;
  313. return (FALSE);
  314. }
  315. /* We now have to calculate the array of print line descriptors for the
  316. header/footer. */
  317. cpMac -= ccpEol;
  318. while (cpMin < cpMac)
  319. {
  320. /* Format this line of the header/footer for the printer. */
  321. FormatLine(docCur, cpMin, ichCp, cpMacDoc, flmPrinting);
  322. /* Bail out if an error occurred. */
  323. if (vfOutOfMemory)
  324. {
  325. return (FALSE);
  326. }
  327. /* Is the array of print line descriptors big enough? */
  328. if (cpld >= cpldMax && !FChngSizeH(*phrgpld, (cpldMax += cpldRH) *
  329. cwPLD, FALSE))
  330. {
  331. return (FALSE);
  332. }
  333. /* Fill the print line descriptor for this line. */
  334. {
  335. register struct PLD *ppld = &(***phrgpld)[cpld++];
  336. ppld->cp = cpMin;
  337. ppld->ichCp = ichCp;
  338. ppld->rc.left = xp + vfli.xpLeft;
  339. ppld->rc.right = xp + vfli.xpReal;
  340. ppld->rc.top = yp;
  341. ppld->rc.bottom = yp + vfli.dypLine;
  342. }
  343. /* Keep track of the non-blank lines in the header/footer */
  344. if ((vfli.ichReal > 0) || vfli.fGraphics)
  345. {
  346. cpldReal = cpld;
  347. }
  348. /* Bump the counters. */
  349. cpMin = vfli.cpMac;
  350. ichCp = vfli.ichCpMac;
  351. yp += vfli.dypLine;
  352. }
  353. /* If this is a footer, then we have to move the positions of the lines
  354. around so that the footer ends where the user has requested. */
  355. if (!fHeader && cpldReal > 0)
  356. {
  357. register struct PLD *ppld = &(***phrgpld)[cpldReal - 1];
  358. int dyp = MultDiv(vsepAbs.yaRH2 - dyaPrOffset, dypPrPage, dyaPrPage)
  359. - ppld->rc.bottom;
  360. int ipld;
  361. for (ipld = cpldReal; ipld > 0; ipld--, ppld--)
  362. {
  363. ppld->rc.top += dyp;
  364. ppld->rc.bottom += dyp;
  365. }
  366. }
  367. /* Record the number of non-blank lines in the head/footer. */
  368. *pcpld = cpldReal;
  369. }
  370. else
  371. {
  372. /* Indicate there is no header/footer. */
  373. *ppgn = pgnNil;
  374. *phrgpld = NULL;
  375. *pcpld = 0;
  376. }
  377. return (TRUE);
  378. }
  379.