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.

1008 lines
30 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* This file contains the printing routines. */
  5. #define NOGDICAPMASKS
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINSTYLES
  8. #define NOSYSMETRICS
  9. #define NOMENUS
  10. #define NOICON
  11. #define NOKEYSTATE
  12. #define NOSYSCOMMANDS
  13. #define NORASTEROPS
  14. #define NOSHOWWINDOW
  15. #define NOATOM
  16. #define NOBITMAP
  17. #define NOBRUSH
  18. #define NOCLIPBOARD
  19. #define NOCOLOR
  20. #define NOCREATESTRUCT
  21. #define NODRAWTEXT
  22. #define NOFONT
  23. #define NOMB
  24. #define NOMEMMGR
  25. #define NOMENUS
  26. #define NOMETAFILE
  27. #define NOOPENFILE
  28. #define NOPEN
  29. #define NOREGION
  30. #define NOSCROLL
  31. #define NOSOUND
  32. #define NOWH
  33. #define NOWINOFFSETS
  34. #define NOWNDCLASS
  35. #define NOCOMM
  36. #include <windows.h>
  37. #include "mw.h"
  38. #include "cmddefs.h"
  39. #include "str.h"
  40. #include "printdef.h"
  41. #include "fmtdefs.h"
  42. #include "docdefs.h"
  43. #include "propdefs.h"
  44. #include "dlgdefs.h"
  45. #include "debug.h"
  46. #include "fontdefs.h"
  47. #if defined(OLE)
  48. #include "obj.h"
  49. #endif
  50. #ifdef INEFFLOCKDOWN
  51. extern FARPROC lpDialogCancelPrint;
  52. extern FARPROC lpFPrContinue;
  53. #else
  54. extern BOOL far PASCAL DialogCancelPrint(HWND, unsigned, WORD, LONG);
  55. extern BOOL far PASCAL FPrContinue(HDC, int);
  56. FARPROC lpFPrContinue;
  57. #endif
  58. BOOL fPrinting;
  59. PrintDoc(doc, fPrint)
  60. int doc;
  61. BOOL fPrint;
  62. {
  63. /* This routine formats the document, doc, for printing and prints it if
  64. fPrint is TRUE. */
  65. BOOL FInitHeaderFooter(BOOL, unsigned *, struct PLD (***)[], int *);
  66. BOOL FSetPage(void);
  67. BOOL FPromptPgMark(typeCP);
  68. BOOL FPrintBand(int, struct PLD (**)[], int, PRECT);
  69. extern BOOL vbCollate;
  70. extern HDC vhDCPrinter;
  71. extern HWND hParentWw;
  72. extern HANDLE hMmwModInstance;
  73. extern struct DOD (**hpdocdod)[];
  74. extern int vpgn;
  75. extern struct SEP vsepAbs;
  76. extern typeCP vcpFirstParaCache;
  77. extern typeCP vcpLimParaCache;
  78. extern typeCP cpMinCur;
  79. extern typeCP cpMinDocument;
  80. extern struct FLI vfli;
  81. extern int wwCur;
  82. extern int docMode;
  83. extern int vdocPageCache;
  84. extern int dxaPrPage;
  85. extern int dyaPrPage;
  86. extern int dxpPrPage;
  87. extern int dypPrPage;
  88. extern int dxaPrOffset;
  89. extern int dyaPrOffset;
  90. extern CHAR szMode[30];
  91. extern int vfRepageConfirm;
  92. extern int vfPrPages; /* true if print page range */
  93. extern int vpgnBegin; /* starting page number to print */
  94. extern int vpgnEnd; /* ending page number to print */
  95. extern int vcCopies; /* nubmer of copies to print */
  96. extern int vfOutOfMemory;
  97. extern BOOL vfPrinterValid;
  98. extern BOOL vfPrErr;
  99. extern BOOL vfDraftMode;
  100. extern CHAR (**hszPrinter)[];
  101. extern CHAR (**hszPrDriver)[];
  102. extern CHAR (**hszPrPort)[];
  103. extern CHAR *vpDlgBuf;
  104. extern HWND vhWndCancelPrint;
  105. extern HCURSOR vhcArrow;
  106. extern HCURSOR vhcIBeam;
  107. LONG lHolder;
  108. int CopyIncr; /* number of copies the printer can print at a time */
  109. typeCP cp;
  110. typeCP cpMin;
  111. typeCP cpMac;
  112. int ichCp;
  113. struct PGD *ppgd;
  114. struct PGTB **hpgtbOld;
  115. int cpld;
  116. unsigned pgnFirst;
  117. unsigned pgnFirstHeader;
  118. unsigned pgnFirstFooter;
  119. int ypTop;
  120. int ypBottom;
  121. int xpLeft;
  122. struct PLD (**hrgpldHeader)[];
  123. struct PLD (**hrgpldFooter)[];
  124. int cpldHeader;
  125. int cpldFooter;
  126. int cCopies,cCollateCopies;
  127. BOOL fConfirm = !fPrint && vfRepageConfirm;
  128. BOOL fSplat;
  129. CHAR stPage[cchMaxIDSTR];
  130. struct PDB pdb;
  131. int iEscape;
  132. #ifndef INEFFLOCKDOWN
  133. FARPROC lpDialogCancelPrint = MakeProcInstance(DialogCancelPrint, hMmwModInstance);
  134. lpFPrContinue = MakeProcInstance(FPrContinue, hMmwModInstance);
  135. if (!lpDialogCancelPrint || !lpFPrContinue)
  136. goto MemoryAbort;
  137. #endif
  138. Assert(vhDCPrinter != NULL);
  139. /* If we are out of memory, we better bail out now. */
  140. if (vfOutOfMemory || vhDCPrinter == NULL)
  141. {
  142. return;
  143. }
  144. /* Disable all other windows. */
  145. EnableWindow(hParentWw, FALSE);
  146. EnableOtherModeless(FALSE);
  147. fPrinting = fPrint;
  148. /* Set some flags associated with printing. */
  149. vfPrErr = pdb.fCancel = FALSE;
  150. /* Set up the print dialog buffer for the repagination or cancellation
  151. dialog boxes. */
  152. vpDlgBuf = (CHAR *)&pdb;
  153. if (fConfirm)
  154. {
  155. /* Reassure the user that we haven't crashed. */
  156. StartLongOp();
  157. }
  158. else
  159. {
  160. /* Bring up the dialog box telling the user how to cancel printing or
  161. repagination. */
  162. if ((vhWndCancelPrint = CreateDialog(hMmwModInstance, fPrint ?
  163. MAKEINTRESOURCE(dlgCancelPrint) : MAKEINTRESOURCE(dlgCancelRepage),
  164. hParentWw, lpDialogCancelPrint)) == NULL)
  165. {
  166. MemoryAbort:
  167. /* Inform the user we cannot print because of a memory failure. */
  168. Error(IDPMTPRFAIL);
  169. vfPrErr = TRUE;
  170. goto Abort;
  171. }
  172. /* Immediately halt if the user requests. */
  173. if (!(*lpFPrContinue)(NULL, wNotSpooler))
  174. {
  175. goto Abort;
  176. }
  177. }
  178. if (fPrint)
  179. {
  180. /* Get the latest printer DC, in case it has changed. */
  181. FreePrinterDC();
  182. GetPrinterDC(TRUE);
  183. if (!vfPrinterValid)
  184. {
  185. goto MemoryAbort;
  186. }
  187. }
  188. /* If we are printing or repaginating without confirmation, then
  189. immediately halt if the user requests. */
  190. if (!fConfirm && !(*lpFPrContinue)(NULL, wNotSpooler))
  191. {
  192. goto Abort;
  193. }
  194. #if defined(OLE)
  195. /*
  196. Load all OLE objects now because loading them
  197. can cause changes in doc layout.
  198. */
  199. {
  200. OBJPICINFO picInfo;
  201. typeCP cpStart=cpNil,cpMac= CpMacText(doc);
  202. struct SEL selSave = selCur;
  203. BOOL bAbort=FALSE,bSetMode=FALSE;
  204. while (ObjPicEnumInRange(&picInfo,doc,cpMinDocument, cpMac, &cpStart))
  205. {
  206. if (lpOBJ_QUERY_INFO(&picInfo) == NULL)
  207. {
  208. Error(IDPMTCantPrint);
  209. bAbort=TRUE;
  210. break;
  211. }
  212. if (lpOBJ_QUERY_OBJECT(&picInfo) == NULL)
  213. {
  214. /* put message in status window */
  215. if (!bSetMode)
  216. {
  217. LoadString(hMmwModInstance, IDSTRLoading, szMode, sizeof(szMode));
  218. DrawMode();
  219. bSetMode=TRUE;
  220. }
  221. if (ObjLoadObjectInDoc(&picInfo,doc,cpStart) == cp0)
  222. {
  223. bAbort=TRUE;
  224. break;
  225. }
  226. }
  227. if (!(*lpFPrContinue)(NULL, wNotSpooler))
  228. {
  229. bAbort=TRUE;
  230. break;
  231. }
  232. }
  233. Select(selSave.cpFirst,selCur.cpLim); // reset
  234. if (bAbort)
  235. {
  236. /* Invalidate the mode so will redraw */
  237. docMode = docNil;
  238. goto Abort;
  239. }
  240. }
  241. #endif
  242. /* Initialize the array of print line descriptors. */
  243. if (FNoHeap(pdb.hrgpld = (struct PLD (**)[])HAllocate((cpld = cpldInit) *
  244. cwPLD)))
  245. {
  246. goto MemoryAbort;
  247. }
  248. /* Get the document properties and set up some local variables. */
  249. CacheSect(doc, cpMin = cpMinDocument);
  250. cpMac = CpMacText(doc);
  251. ypTop = MultDiv(vsepAbs.yaTop - dyaPrOffset, dypPrPage, dyaPrPage);
  252. ypBottom = MultDiv(vsepAbs.yaTop + vsepAbs.dyaText - dyaPrOffset, dypPrPage,
  253. dyaPrPage);
  254. xpLeft = MultDiv(vsepAbs.xaLeft - dxaPrOffset, dxpPrPage, dxaPrPage);
  255. vdocPageCache = docNil;
  256. /* Initialize the page table. */
  257. if (FNoHeap(pdb.hpgtb = (struct PGTB **)HAllocate(cwPgtbBase + cpgdChunk *
  258. cwPGD)))
  259. {
  260. /* Not enough memory for page table; time to bail out. */
  261. FreeH(pdb.hpgtb);
  262. goto MemoryAbort;
  263. }
  264. (**pdb.hpgtb).cpgdMax = cpgdChunk;
  265. (**pdb.hpgtb).cpgd = 1;
  266. ppgd = &((**pdb.hpgtb).rgpgd[0]);
  267. ppgd->cpMin = cpMin;
  268. if ((pgnFirst = vsepAbs.pgnStart) == pgnNil)
  269. {
  270. pgnFirst = 1;
  271. }
  272. ppgd->pgn = pgnFirst;
  273. /* Ensure that szMode says "Page ". */
  274. FillStId(stPage, IDSTRChPage, sizeof(stPage));
  275. #if !defined(KOREA)
  276. stPage[1] = ChUpper(stPage[1]);
  277. stPage[stPage[0] + 1] = ' ';
  278. bltbyte(&stPage[1], szMode, ++stPage[0]);
  279. #endif
  280. /* Attatch the new page table to the document. */
  281. {
  282. register struct DOD *pdod = &(**hpdocdod)[doc];
  283. hpgtbOld = pdod->hpgtb;
  284. pdod->hpgtb = pdb.hpgtb;
  285. }
  286. /* Set cpMinCur to cp0 for the duration of the print. */
  287. Assert(cpMinCur == cpMinDocument);
  288. cpMinCur = cp0;
  289. /* If we are printing or repaginating without confirmation, then
  290. immediately halt if the user requests. */
  291. if (!fConfirm && !(*lpFPrContinue)(NULL, wNotSpooler))
  292. {
  293. goto ErrorNoAbort;
  294. }
  295. if (fPrint)
  296. {
  297. CHAR stTitle[cchMaxIDSTR];
  298. /* Set up the variables that describe the header. */
  299. if (!FInitHeaderFooter(TRUE, &pgnFirstHeader, &hrgpldHeader,
  300. &cpldHeader))
  301. {
  302. Error(IDPMTPRFAIL);
  303. goto ErrorNoAbort;
  304. }
  305. /* Set up the variables that describe the footer. */
  306. if (!FInitHeaderFooter(FALSE, &pgnFirstFooter, &hrgpldFooter,
  307. &cpldFooter))
  308. {
  309. Error(IDPMTPRFAIL);
  310. goto ErrorNoAbort;
  311. }
  312. /* Set the name of the function called to query whether the print should
  313. be aborted. */
  314. Escape(vhDCPrinter, SETABORTPROC, sizeof(FARPROC), (LPSTR)lpFPrContinue,
  315. (LPSTR)NULL);
  316. /* Set the printer into draft mode if necessary. */
  317. if (vfDraftMode)
  318. {
  319. Escape(vhDCPrinter, DRAFTMODE, sizeof(BOOL), (LPSTR)&vfDraftMode,
  320. (LPSTR)NULL);
  321. }
  322. /* Inform the spooler that we are about to print. */
  323. stTitle[0] = GetWindowText(hParentWw, (LPSTR)&stTitle[1],
  324. sizeof(stTitle) - 1) + 1;
  325. if ((iEscape = Escape(vhDCPrinter, STARTDOC, stTitle[0],
  326. (LPSTR)&stTitle[1], (LPSTR)NULL)) < 0)
  327. {
  328. ErrorSwitch:
  329. switch (iEscape)
  330. {
  331. default:
  332. if ((iEscape & SP_NOTREPORTED) == 0)
  333. {
  334. break;
  335. }
  336. case SP_ERROR:
  337. Error(IDPMTCantPrint);
  338. break;
  339. case SP_APPABORT:
  340. case SP_USERABORT:
  341. break;
  342. case SP_OUTOFDISK:
  343. Error(IDPMTPrDiskErr);
  344. break;
  345. case SP_OUTOFMEMORY:
  346. Error(IDPMTPRFAIL);
  347. break;
  348. }
  349. goto ErrorNoAbort;
  350. }
  351. }
  352. #ifdef DPRINT
  353. CommSzSz("Start doc", "");
  354. #endif
  355. /* If we are printing or repaginating without confirmation, then
  356. immediately halt if the user requests. */
  357. if (!fConfirm && !(*lpFPrContinue)(NULL, wNotSpooler))
  358. {
  359. goto Error;
  360. }
  361. // vcCopies is how many times to print each page
  362. // cCollateCopies is how many times to print the doc
  363. if (vbCollate && fPrint)
  364. {
  365. cCollateCopies = vcCopies;
  366. vcCopies = 1;
  367. }
  368. else
  369. cCollateCopies = 1;
  370. /* And away we go... */
  371. while (cCollateCopies--)
  372. {
  373. cCopies = 0;
  374. /*------------------------------------------------*/
  375. /* Tell the driver how many copies we want */
  376. /*------------------------------------------------*/
  377. lHolder = SETCOPYCOUNT;
  378. /* Set number of copies the printer can print */
  379. CopyIncr = vcCopies;
  380. if (Escape(vhDCPrinter, QUERYESCSUPPORT, 2, (LPSTR) &lHolder, NULL))
  381. Escape(vhDCPrinter, SETCOPYCOUNT, 2, (LPSTR) &CopyIncr, (LPSTR) &CopyIncr);
  382. else
  383. CopyIncr = 1;
  384. do
  385. {
  386. /* Initalize the counters to the beginning of the document. */
  387. cp = cpMin;
  388. ichCp = 0;
  389. vpgn = pgnFirst;
  390. /* Step through the document, formatting a page and then printing a
  391. page. */
  392. while (cp < cpMac)
  393. {
  394. register struct PLD *ppld;
  395. CHAR *pch;
  396. int yp = ypTop;
  397. BOOL fPageAdj = FALSE;
  398. /* If only a range of pages are being printed, then stop when the
  399. last of the pages are printed. */
  400. if (fPrint && vfPrPages && vpgn > vpgnEnd)
  401. {
  402. goto DocFinished;
  403. }
  404. /* Show the page number we are formatting and printing. */
  405. #if defined(KOREA)
  406. pch = &szMode[0];
  407. *pch++ = ' ';
  408. ncvtu(vpgn, &pch);
  409. *pch++ = ' ';
  410. bltbyte(&stPage[1], pch, stPage[0]+1);
  411. #else
  412. pch = &szMode[stPage[0]];
  413. ncvtu(vpgn, &pch);
  414. *pch = '\0';
  415. #endif
  416. DrawMode();
  417. /* Let's go through the document page by page. */
  418. pdb.ipld = 0;
  419. while (cp < cpMac)
  420. {
  421. /* If we are printing or repaginating without confirmation, then
  422. immediately halt if the user requests. */
  423. if (!fConfirm && !(*lpFPrContinue)(NULL, wNotSpooler))
  424. {
  425. goto Error;
  426. }
  427. /* We have reached the end of the line descriptors; try to
  428. increase its size. */
  429. if (pdb.ipld >= cpld && !FChngSizeH(pdb.hrgpld, (cpld +=
  430. cpldChunk) * cwPLD, FALSE))
  431. {
  432. goto Error;
  433. }
  434. PrintFormat:
  435. /* Format this line. */
  436. FormatLine(doc, cp, ichCp, cpMac, flmPrinting);
  437. /* Abort if a memory error has occurred. */
  438. if (vfOutOfMemory)
  439. {
  440. goto Error;
  441. }
  442. /* If this line is a splat, we have to decide if we really want
  443. it or not. */
  444. if (fSplat = vfli.fSplat)
  445. {
  446. /* Next, we are going to format either the next line (cp and
  447. ichCp) or this line after the page has been removed (cpT and
  448. ichCpT). */
  449. typeCP cpT = cp;
  450. int ichCpT = ichCp;
  451. cp = vfli.cpMac;
  452. ichCp = vfli.ichCpMac;
  453. if (fConfirm)
  454. {
  455. /* The user must be prompted if he wants to keep this
  456. page break. */
  457. if (FPromptPgMark(cpT))
  458. {
  459. if (pdb.fRemove)
  460. {
  461. /* The page mark was removed, set cp and ichCp
  462. to point to the start of the next line. */
  463. cp = cpT;
  464. ichCp = ichCpT;
  465. cpMac--;
  466. goto PrintFormat;
  467. }
  468. }
  469. else
  470. {
  471. if (vfPrErr)
  472. {
  473. /* Something went wrong; punt. */
  474. goto Error;
  475. }
  476. else
  477. {
  478. /* Well, the user wishes to cancel repagination.
  479. */
  480. goto CancelRepage;
  481. }
  482. }
  483. }
  484. /* Set the print line descriptor for the line after a splat.
  485. */
  486. ppld = &(**pdb.hrgpld)[pdb.ipld];
  487. ppld->cp = cp;
  488. ppld->ichCp = ichCp;
  489. ppld->rc.left = ppld->rc.top = ppld->rc.right =
  490. ppld->rc.bottom = 0;
  491. /* Force a page break here with no widow and orphan
  492. control. */
  493. goto BreakPage;
  494. }
  495. /* Set the value for the current print line descriptor. */
  496. ppld = &(**pdb.hrgpld)[pdb.ipld];
  497. ppld->cp = cp;
  498. ppld->ichCp = ichCp;
  499. ppld->rc.left = xpLeft + vfli.xpLeft;
  500. ppld->rc.right = xpLeft + vfli.xpReal;
  501. ppld->rc.top = yp;
  502. ppld->rc.bottom = yp + vfli.dypLine;
  503. ppld->fParaFirst = (cp == vcpFirstParaCache && ichCp == 0 &&
  504. vfli.cpMac != vcpLimParaCache);
  505. /* If this line is not the first line and it won't fit on the
  506. page, then force a page break, and prompt the user for input.
  507. NOTE: At least one line is printed on each page. */
  508. if (yp + vfli.dypLine > ypBottom && pdb.ipld > 0)
  509. {
  510. /* If the first line on the next page is the last line of a
  511. paragraph, an orphan, then put the last line of this page on
  512. the next page. */
  513. if (vfli.cpMac == vcpLimParaCache && (cp !=
  514. vcpFirstParaCache || ichCp != 0) && pdb.ipld > 1)
  515. {
  516. pdb.ipld--;
  517. fPageAdj = TRUE;
  518. }
  519. /* If the last line on this page is the first line of a
  520. paragraph, a widow, then put it on the next page. */
  521. if (pdb.ipld > 1 && (**pdb.hrgpld)[pdb.ipld - 1].fParaFirst)
  522. {
  523. pdb.ipld--;
  524. fPageAdj = TRUE;
  525. }
  526. BreakPage:
  527. /* Add an entry into the page table (only during the first
  528. copy of the document). */
  529. if (cCopies == 0)
  530. {
  531. if ((pdb.ipgd = (**pdb.hpgtb).cpgd++) + 1 >=
  532. (**pdb.hpgtb).cpgdMax)
  533. {
  534. if (!FChngSizeH(pdb.hpgtb, cwPgtbBase +
  535. ((**pdb.hpgtb).cpgdMax += cpgdChunk) * cwPGD,
  536. FALSE))
  537. {
  538. /* Not enough memory to expand the page table;
  539. time to bail out. */
  540. goto ErrorMsg;
  541. }
  542. }
  543. ppgd = &((**pdb.hpgtb).rgpgd[pdb.ipgd]);
  544. ppgd->cpMin = (**pdb.hrgpld)[pdb.ipld].cp;
  545. ppgd->pgn = vpgn + 1;
  546. vdocPageCache = docNil;
  547. }
  548. /* Now go ask the user for his opinion. */
  549. if (fConfirm)
  550. {
  551. if (!fSplat)
  552. {
  553. pdb.ipldCur = pdb.ipld;
  554. if (FSetPage())
  555. {
  556. if (pdb.ipld != pdb.ipldCur)
  557. {
  558. /* The user has decided to move the page
  559. break. */
  560. pdb.ipld = pdb.ipldCur;
  561. cpMac++;
  562. fPageAdj = TRUE;
  563. }
  564. }
  565. else
  566. {
  567. if (vfPrErr)
  568. {
  569. /* Something went wrong; punt. */
  570. goto Error;
  571. }
  572. else
  573. {
  574. /* Well, the user wishes to cancel
  575. repagination. */
  576. goto CancelRepage;
  577. }
  578. }
  579. }
  580. /* After repaginating interactively, make certain the
  581. screen reflects the current page break. */
  582. UpdateWw(wwCur, FALSE);
  583. }
  584. /* This page has finished formatting, reset the cp and ichCp
  585. pair to the top of the next page if necessary and get out of
  586. this loop. */
  587. if (fPageAdj)
  588. {
  589. ppld = &(**pdb.hrgpld)[pdb.ipld];
  590. cp = ppld->cp;
  591. ichCp = ppld->ichCp;
  592. }
  593. break;
  594. }
  595. /* Set the cp and ichCp to the start of the next line. */
  596. cp = vfli.cpMac;
  597. ichCp = vfli.ichCpMac;
  598. yp += vfli.dypLine;
  599. pdb.ipld++;
  600. }
  601. /* Now that we have figured out which lines fit on the page, its
  602. time to print them. */
  603. if (fPrint && (!vfPrPages || (vpgn >= vpgnBegin && vpgn <=
  604. vpgnEnd)))
  605. {
  606. BOOL fFirstBand = TRUE;
  607. /* This loop is executed for each band (once for non-banding
  608. devices). */
  609. for ( ; ; )
  610. {
  611. RECT rcBand;
  612. /* Abort the print if the user so desires. */
  613. if (!(*lpFPrContinue)(NULL, wNotSpooler))
  614. {
  615. goto Error;
  616. }
  617. /* Get the next band. */
  618. if ((iEscape = Escape(vhDCPrinter, NEXTBAND, 0,
  619. (LPSTR)NULL, (LPSTR)&rcBand)) < 0)
  620. {
  621. goto ErrorSwitch;
  622. }
  623. #ifdef DPRINT
  624. CommSzSz("Next band", "");
  625. #endif
  626. /* If the band is empty then we are finished with this
  627. page. */
  628. if (rcBand.top >= rcBand.bottom || rcBand.left >=
  629. rcBand.right)
  630. {
  631. /* Reset the currently selected font. */
  632. ResetFont(TRUE);
  633. break;
  634. }
  635. /* The printer DC gets wiped clean at the start of each
  636. page. It must be reinitialized. */
  637. if (fFirstBand)
  638. {
  639. /* Set the printer into transparent mode. */
  640. SetBkMode(vhDCPrinter, TRANSPARENT);
  641. /* Reset the currently selected font. */
  642. ResetFont(TRUE);
  643. fFirstBand = FALSE;
  644. }
  645. /* First, print the header, if there is one. */
  646. if (vpgn >= pgnFirstHeader && !FPrintBand(doc,
  647. hrgpldHeader, cpldHeader, &rcBand))
  648. {
  649. goto Error;
  650. }
  651. /* Print that part of the document that lies in the
  652. band. */
  653. if (!FPrintBand(doc, pdb.hrgpld, pdb.ipld, &rcBand))
  654. {
  655. goto Error;
  656. }
  657. /* Lastly, print the footer, if it exists. */
  658. if (vpgn >= pgnFirstFooter && !FPrintBand(doc,
  659. hrgpldFooter, cpldFooter, &rcBand))
  660. {
  661. goto Error;
  662. }
  663. }
  664. }
  665. /* Finally, bump the page counter. */
  666. vpgn++;
  667. }
  668. DocFinished:;
  669. }
  670. while (fPrint && (cCopies += CopyIncr) < vcCopies);
  671. }
  672. /* If a range of pages is being printed then we reattatch the old page table
  673. to the document. */
  674. if (fPrint && vfPrPages)
  675. {
  676. goto RestorePgtb;
  677. }
  678. CancelRepage:
  679. /* If the page table has changed, then mark the document as dirty. */
  680. if (!(**hpdocdod)[doc].fDirty)
  681. {
  682. (**hpdocdod)[doc].fDirty = (hpgtbOld == NULL) || ((**pdb.hpgtb).cpgd !=
  683. (**hpgtbOld).cpgd) || !FRgchSame((**pdb.hpgtb).rgpgd,
  684. (**hpgtbOld).rgpgd, (**pdb.hpgtb).cpgd * cchPGD);
  685. }
  686. /* Delete the old page table. */
  687. if (hpgtbOld != NULL)
  688. {
  689. FreeH(hpgtbOld);
  690. }
  691. /* Printing and non-interactive repagination can't be undone. */
  692. if (!fConfirm)
  693. {
  694. NoUndo();
  695. }
  696. ErrorLoop:
  697. /* Delete the array of line descriptors. */
  698. FreeH(pdb.hrgpld);
  699. if (fPrint)
  700. {
  701. BOOL fResetMode = FALSE;
  702. /* Delete the descriptors for the header and footer. */
  703. if (hrgpldHeader != NULL)
  704. {
  705. FreeH(hrgpldHeader);
  706. }
  707. if (hrgpldFooter != NULL)
  708. {
  709. FreeH(hrgpldFooter);
  710. }
  711. /* Tell the spooler that we are finished printing. */
  712. if (!vfPrErr)
  713. {
  714. Escape(vhDCPrinter, ENDDOC, 0, (LPSTR)NULL, (LPSTR)NULL);
  715. #ifdef DPRINT
  716. CommSzSz("End doc", "");
  717. #endif
  718. }
  719. /* Reset the printer from draft mode if necessary. */
  720. if (vfDraftMode)
  721. {
  722. Escape(vhDCPrinter, DRAFTMODE, sizeof(BOOL), (LPSTR)&fResetMode,
  723. (LPSTR)NULL);
  724. }
  725. }
  726. /* Reset the value of cpMinCur. */
  727. cpMinCur = cpMin;
  728. /* Invalidate the mode and page caches. */
  729. docMode = vdocPageCache = docNil;
  730. /* Since this might have changed the page breaks, dirty the windows so that
  731. UpdateDisplay() will show them. */
  732. TrashAllWws();
  733. Abort:
  734. if (fPrint)
  735. {
  736. /* Create a new IC for the printer. */
  737. ResetFont(TRUE);
  738. FreePrinterDC();
  739. GetPrinterDC(FALSE);
  740. }
  741. /* Enable all other windows. */
  742. EnableWindow(hParentWw, TRUE);
  743. EnableOtherModeless(TRUE);
  744. if (fConfirm)
  745. {
  746. /* Let the user know that we are finished repaginating. */
  747. EndLongOp(vhcIBeam);
  748. }
  749. else if (vhWndCancelPrint != NULL)
  750. {
  751. /* Get rid of the dialog box telling the user how to cancel printing or
  752. repagination. */
  753. DestroyWindow(vhWndCancelPrint);
  754. vhWndCancelPrint = NULL;
  755. DispatchPaintMsg();
  756. }
  757. #ifndef INEFFLOCKDOWN
  758. if (lpDialogCancelPrint)
  759. FreeProcInstance(lpDialogCancelPrint);
  760. if (lpFPrContinue)
  761. FreeProcInstance(lpFPrContinue);
  762. lpDialogCancelPrint = lpFPrContinue = NULL;
  763. #endif
  764. fPrinting = FALSE;
  765. #if defined(OLE)
  766. UPDATE_INVALID(); /* WM_PAINTS blocked while printing, repaint when done */
  767. #endif
  768. /* Here is the exit point for this routine. */
  769. return;
  770. ErrorMsg:
  771. /* Give the user an error message before aborting the print/repagination. */
  772. Error(IDPMTPRFAIL);
  773. Error:
  774. /* Abort the print job if necessary. */
  775. if (fPrint)
  776. {
  777. Escape(vhDCPrinter, ABORTDOC, 0, (LPSTR)NULL, (LPSTR)NULL);
  778. #ifdef DPRINT
  779. CommSzSz("Abort doc", "");
  780. #endif
  781. }
  782. ErrorNoAbort:
  783. /* Indicate that an error has occurred. (Cancellation is an error.) */
  784. vfPrErr = TRUE;
  785. RestorePgtb:
  786. /* Reconnect to old page table to the document, and then delete the new
  787. page table. */
  788. (**hpdocdod)[doc].hpgtb = hpgtbOld;
  789. FreeH(pdb.hpgtb);
  790. goto ErrorLoop;
  791. }
  792. BOOL far PASCAL FPrContinue(hDC, iCode)
  793. HDC hDC;
  794. int iCode;
  795. {
  796. /* This routine returns TRUE if the user has not aborted the print; FALSE
  797. otherwise. */
  798. extern CHAR *vpDlgBuf;
  799. extern HWND vhWndCancelPrint;
  800. extern BOOL vfPrErr;
  801. extern int vfOutOfMemory;
  802. struct PDB *ppdb = (struct PDB *)vpDlgBuf;
  803. MSG msg;
  804. #if 0
  805. /* If a printer error has occurred, that is the same as an abort. */
  806. if (vfPrErr || vfOutOfMemory || (iCode < 0 && iCode != SP_OUTOFDISK))
  807. {
  808. return (FALSE);
  809. }
  810. /* If we have been called by the spooler then just return TRUE.
  811. (Calling PeekMessage() at this point might be death.) */
  812. if (iCode != wNotSpooler)
  813. {
  814. Assert(iCode == 0 || iCode == SP_OUTOFDISK);
  815. if (iCode == 0)
  816. return (TRUE);
  817. /* else fall through to wait -- we're getting called by GDI while
  818. the spooler frees up some temp files. this is NOT a genuine
  819. error yet! 12/20/89 ..pault */
  820. }
  821. #else
  822. if (vfPrErr || vfOutOfMemory)
  823. return FALSE;
  824. #endif
  825. /* If there are any messages waiting the Cancel Print window, then send them
  826. to the window messages handling routine. */
  827. while (!ppdb->fCancel && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  828. {
  829. if (!IsDialogMessage(vhWndCancelPrint, &msg))
  830. {
  831. TranslateMessage(&msg);
  832. DispatchMessage(&msg);
  833. }
  834. }
  835. /* If one of the messages was a cancel print meassge, then the value of
  836. fCancel has been set. */
  837. return !(vfPrErr = ppdb->fCancel || vfOutOfMemory);
  838. }
  839. BOOL far PASCAL DialogCancelPrint(hWnd, message, wParam, lParam)
  840. HWND hWnd;
  841. unsigned message;
  842. WORD wParam;
  843. LONG lParam;
  844. {
  845. /* This routine is supposed to process messages to the Cancel Print dialog
  846. box, but, in reality, the sole responsiblity of this routine is to set the
  847. flag fCancel if the user wishes to cancel printing. */
  848. extern CHAR *vpDlgBuf;
  849. extern HWND vhWndMsgBoxParent;
  850. struct PDB *ppdb = (struct PDB *)vpDlgBuf;
  851. if ((message == WM_COMMAND && (wParam == idiCancel || wParam == idiOk)) ||
  852. (message == WM_CLOSE))
  853. {
  854. ppdb->fCancel = TRUE;
  855. return (TRUE);
  856. }
  857. if (message == WM_INITDIALOG)
  858. {
  859. extern int docCur;
  860. extern char szUntitled[];
  861. extern struct DOD (**hpdocdod)[];
  862. extern char * PchStartBaseNameSz();
  863. struct DOD *pdod = &(**hpdocdod)[docCur];
  864. CHAR *psz = &(**(pdod->hszFile))[0];
  865. SetDlgItemText(hWnd, idiPrCancelName,
  866. (LPSTR)(*psz ? PchStartBaseNameSz(psz) : szUntitled));
  867. return(TRUE);
  868. }
  869. if (message == WM_ACTIVATE)
  870. {
  871. vhWndMsgBoxParent = wParam == 0 ? (HWND)NULL : hWnd;
  872. }
  873. return (FALSE);
  874. }
  875. DispatchPaintMsg()
  876. {
  877. /* This routine looks for and dispatches any outstanding paint messages for
  878. Write (like after an EndDialog() call). */
  879. extern int vfOutOfMemory;
  880. MSG msg;
  881. while (!vfOutOfMemory && PeekMessage((LPMSG)&msg, NULL, WM_PAINT, WM_PAINT,
  882. PM_REMOVE))
  883. {
  884. DispatchMessage((LPMSG)&msg);
  885. }
  886. }