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.

335 lines
9.7 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOCLIPBOARD
  5. #define NOGDICAPMASKS
  6. #define NOCTLMGR
  7. #define NOWINSTYLES
  8. #define NOWINMESSAGES
  9. #define NOVIRTUALKEYCODES
  10. #define NOSYSMETRICS
  11. #define NOMENUS
  12. #define NOGDI
  13. #define NOKEYSTATE
  14. #define NOHDC
  15. #define NOGDI
  16. #define NORASTEROPS
  17. #define NOSYSCOMMANDS
  18. #define NOSHOWWINDOW
  19. #define NOCOLOR
  20. #define NOATOM
  21. #define NOBITMAP
  22. #define NOICON
  23. #define NOBRUSH
  24. #define NOCREATESTRUCT
  25. #define NOMB
  26. #define NOFONT
  27. #define NOMSG
  28. #define NOOPENFILE
  29. #define NOPEN
  30. #define NOPOINT
  31. #define NORECT
  32. #define NOREGION
  33. #define NOSCROLL
  34. #define NOSOUND
  35. #define NOWH
  36. #define NOWINOFFSETS
  37. #define NOWNDCLASS
  38. #define NOCOMM
  39. #include <windows.h>
  40. #include "mw.h"
  41. #include "cmddefs.h"
  42. #define NOKCCODES
  43. #include "ch.h"
  44. #include "docdefs.h"
  45. #include "prmdefs.h"
  46. #include "propdefs.h"
  47. #include "filedefs.h"
  48. #include "stcdefs.h"
  49. #include "fkpdefs.h"
  50. #include "editdefs.h"
  51. #include "wwdefs.h"
  52. #include "dispdefs.h"
  53. /* E X T E R N A L S */
  54. extern struct WWD rgwwd[];
  55. extern int docCur;
  56. extern struct CHP vchpFetch;
  57. extern struct CHP vchpInsert;
  58. extern struct CHP vchpSel;
  59. extern struct CHP vchpNormal;
  60. extern struct FKPD vfkpdParaIns;
  61. extern typeFC fcMacPapIns;
  62. extern struct PAP *vppapNormal;
  63. extern struct PAP vpapPrevIns;
  64. extern struct FCB (**hpfnfcb)[];
  65. extern struct BPS *mpibpbps;
  66. extern CHAR (*rgbp)[cbSector];
  67. extern typePN PnAlloc();
  68. InsertRgch(doc, cp, rgch, cch, pchp, ppap)
  69. int doc, cch;
  70. typeCP cp;
  71. CHAR rgch[];
  72. struct CHP *pchp;
  73. struct PAP *ppap;
  74. { /* Insert cch characters from rgch into doc before cp */
  75. typeFC fc;
  76. struct CHP chp;
  77. /* First finish off the previous CHAR run if necessary */
  78. if (pchp == 0)
  79. { /* Make looks be those of PREVIOUS character */
  80. CachePara(doc,cp);
  81. FetchCp(doc, CpMax(cp0, cp - 1), 0, fcmProps);
  82. blt(&vchpFetch, &chp, cwCHP);
  83. chp.fSpecial = false;
  84. pchp = &chp;
  85. }
  86. NewChpIns(pchp);
  87. /* Now write the characters to the scratch file */
  88. fc = FcWScratch(rgch, cch);
  89. /* Now insert a paragraph run if we inserted an EOL */
  90. if (ppap != 0)
  91. { /* Inserting EOL--must be last character of rgch */
  92. AddRunScratch(&vfkpdParaIns, ppap, vppapNormal,
  93. FParaEq(ppap, &vpapPrevIns) &&
  94. vfkpdParaIns.brun != 0 ? -cchPAP : cchPAP,
  95. fcMacPapIns = (**hpfnfcb)[fnScratch].fcMac);
  96. blt(ppap, &vpapPrevIns, cwPAP);
  97. }
  98. /* Finally, insert the piece into the document */
  99. Replace(doc, cp, cp0, fnScratch, fc, (typeFC) cch);
  100. }
  101. InsertEolInsert(doc,cp)
  102. int doc;
  103. typeCP cp;
  104. {
  105. struct PAP papT;
  106. struct CHP chpT;
  107. CHAR rgch[2];
  108. /* (MEMO) Here's the problem: When we insert or paste into a running head or
  109. foot, we expect all paras to have a non-0 rhc. This gets called from
  110. Replace to put in an Eol when we are inserting or pasting in front of
  111. a picture. It needs, therefore, to have running head properties when
  112. appropriate. In a future world, cpMinDocument, cpMinHeader, cpMacHeader,
  113. cpMinFooter, and cpMacFooter will be document attributes instead of
  114. globals, and will be duly adjusted by AdjustCp. Then, we can trash the
  115. somewhat kludgy check for doc==docCur and editing header/footer,
  116. and instead check for cp within header/footer bounds for doc. */
  117. papT = *vppapNormal;
  118. if (doc==docCur)
  119. if (wwdCurrentDoc.fEditHeader)
  120. papT.rhc = RHC_fOdd + RHC_fEven;
  121. else if (wwdCurrentDoc.fEditFooter)
  122. papT.rhc = RHC_fBottom + RHC_fOdd + RHC_fEven;
  123. #ifdef CRLF
  124. rgch[0] = chReturn;
  125. rgch[1] = chEol;
  126. chpT = vchpSel;
  127. chpT.fSpecial = fFalse;
  128. InsertRgch(doc, cp, rgch, 2, &chpT, &papT);
  129. #else
  130. rgch[0] = chEol;
  131. chpT = vchpSel;
  132. chpT.fSpecial = fFalse;
  133. InsertRgch(doc, cp, rgch, 1, &chpT, &papT);
  134. #endif
  135. }
  136. InsertEolPap(doc, cp, ppap)
  137. int doc;
  138. typeCP cp;
  139. struct PAP *ppap;
  140. {
  141. extern struct CHP vchpAbs;
  142. struct CHP chpT;
  143. #ifdef CRLF
  144. CHAR rgch [2];
  145. #else
  146. CHAR rgch [1];
  147. #endif
  148. /* We must get props here instead of using vchpNormal because of the
  149. "10-point kludge". We don't want to change the default font
  150. just because we have to insert a new pap */
  151. FetchCp( doc, cp, 0, fcmProps );
  152. chpT = vchpAbs;
  153. chpT.fSpecial = fFalse;
  154. #ifdef CRLF
  155. rgch [0] = chReturn;
  156. rgch [1] = chEol;
  157. InsertRgch(doc, cp, rgch, 2, &chpT, ppap);
  158. #else
  159. InsertRgch(doc, cp, rgch, 1, &chpT, ppap);
  160. #endif
  161. }
  162. AddRunScratch(pfkpd, pchProp, pchStd, cchProp, fcLim)
  163. struct FKPD *pfkpd;
  164. CHAR *pchProp, *pchStd;
  165. int cchProp;
  166. typeFC fcLim;
  167. { /* Add a CHAR or para run to the scratch file FKP (see FAddRun) */
  168. struct FKP *pfkp;
  169. CHAR *pchFprop;
  170. struct RUN *prun;
  171. int ibp;
  172. pfkp = (struct FKP *) rgbp[ibp = IbpEnsureValid(fnScratch, pfkpd->pn)];
  173. pchFprop = &pfkp->rgb[pfkpd->bchFprop];
  174. prun = (struct RUN *) &pfkp->rgb[pfkpd->brun];
  175. while (!FAddRun(fnScratch, pfkp, &pchFprop, &prun, pchProp, pchStd, cchProp,
  176. fcLim))
  177. { /* Go to a new page; didn't fit. */
  178. int ibte = pfkpd->ibteMac;
  179. struct BTE (**hgbte)[] = pfkpd->hgbte;
  180. /* Create new entry in bin table for filled page */
  181. if (!FChngSizeH(hgbte, ((pfkpd->ibteMac = ibte + 1) * sizeof (struct BTE)) / sizeof (int),
  182. false))
  183. return;
  184. (**hgbte)[ibte].fcLim = (prun - 1)->fcLim;
  185. (**hgbte)[ibte].pn = pfkpd->pn;
  186. /* Allocate new page */
  187. pfkpd->pn = PnAlloc(fnScratch);
  188. pfkpd->brun = 0;
  189. pfkpd->bchFprop = cbFkp;
  190. if (cchProp < 0) /* New page, so force output of fprop */
  191. cchProp = -cchProp;
  192. /* Reset pointers and fill in fcFirst */
  193. pfkp = (struct FKP *) rgbp[ibp = IbpEnsureValid(fnScratch, pfkpd->pn)];
  194. pfkp->fcFirst = (prun - 1)->fcLim;
  195. pchFprop = &pfkp->rgb[pfkpd->bchFprop];
  196. prun = (struct RUN *) &pfkp->rgb[pfkpd->brun];
  197. }
  198. mpibpbps[ibp].fDirty = true;
  199. pfkpd->brun = (CHAR *) prun - &pfkp->rgb[0];
  200. pfkpd->bchFprop = pchFprop - &pfkp->rgb[0];
  201. }
  202. int FAddRun(fn, pfkp, ppchFprop, pprun, pchProp, pchStd, cchProp, fcLim)
  203. int fn, cchProp;
  204. struct FKP *pfkp;
  205. CHAR **ppchFprop, *pchProp, *pchStd;
  206. struct RUN **pprun;
  207. typeFC fcLim;
  208. { /* Add a run and FCHP/FPAP to the current FKP. */
  209. /* Make a new page if it won't fit. */
  210. /* If cchProp < 0, don't make new fprop if page not full */
  211. int cch;
  212. /* If there's not even enough room for a run, force new fprop */
  213. if (cchProp < 0 && (CHAR *) (*pprun + 1) > *ppchFprop)
  214. cchProp = -cchProp;
  215. if (cchProp > 0)
  216. { /* Make a new fprop */
  217. /* Compute length of FPAP/FCHP */
  218. if (cchProp == cchPAP)
  219. {
  220. /* compute difference from vppapNormal */
  221. if (((struct PAP *)pchProp)->rgtbd[0].dxa != 0)
  222. {
  223. int itbd;
  224. /* find end of tab table */
  225. for (itbd = 1; itbd < itbdMax; itbd++)
  226. if (((struct PAP *)pchProp)->rgtbd[itbd].dxa == 0)
  227. {
  228. cch = cwPAPBase * cchINT + (itbd + 1) * cchTBD;
  229. goto HaveCch;
  230. }
  231. }
  232. cchProp = cwPAPBase * cchINT;
  233. }
  234. cch = CchDiffer(pchProp, pchStd, cchProp);
  235. HaveCch:
  236. if (cch > 0)
  237. ++cch;
  238. /* Determine whether info will fit on this page */
  239. if ((CHAR *) (*pprun + 1) > *ppchFprop - cch)
  240. { /* Go to new page; this one is full */
  241. if (fn == fnScratch)
  242. return false; /* Let AddRunScratch handle this */
  243. WriteRgch(fn, pfkp, cbSector);
  244. pfkp->fcFirst = (*pprun - 1)->fcLim;
  245. *ppchFprop = &pfkp->rgb[cbFkp];
  246. *pprun = (struct RUN *) pfkp->rgb;
  247. }
  248. /* If new FPAP is needed, make it */
  249. if (cch > 0)
  250. {
  251. (*pprun)->b = (*ppchFprop -= cch) - pfkp->rgb;
  252. **ppchFprop = --cch;
  253. bltbyte(pchProp, *ppchFprop + 1, cch);
  254. }
  255. else /* Use standard props */
  256. (*pprun)->b = bNil;
  257. }
  258. else /* Point to previous fprop */
  259. (*pprun)->b = (*pprun - 1)->b;
  260. /* Replaced old sequence (see below) */
  261. (*pprun)->fcLim = fcLim;
  262. pfkp->crun = ++(*pprun) - (struct RUN *) pfkp->rgb;
  263. /* Used to be like this, but CMERGE -Oa (assume no aliasing)
  264. option made it not work -- "*pprun" is an alias for the
  265. postincremented value of *pprun */
  266. /*(*pprun)++->fcLim = fcLim;
  267. pfkp->crun = *pprun - (struct RUN *) pfkp->rgb; */
  268. return true;
  269. }
  270. /* F P A R A E Q */
  271. /* compares two PAP structures. Problem: tab tables are not fixed length
  272. but are terminated by 0 dxa. */
  273. FParaEq(ppap1, ppap2)
  274. struct PAP *ppap1, *ppap2;
  275. {
  276. struct TBD *ptbd1 = ppap1->rgtbd, *ptbd2 = ppap2->rgtbd;
  277. while (ptbd1->dxa == ptbd2->dxa)
  278. {
  279. if (ptbd1->dxa == 0)
  280. return CchDiffer(ppap1, ppap2, cchPAP) == 0;
  281. if (*(long *)ptbd1 != *(long *)ptbd2) break;
  282. ptbd1++; ptbd2++;
  283. }
  284. return fFalse;
  285. }
  286.