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.

241 lines
7.4 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOCLIPBOARD
  5. #define NOGDICAPMASKS
  6. #define NOCTLMGR
  7. #define NOVIRTUALKEYCODES
  8. #define NOWINMESSAGES
  9. #define NOWINSTYLES
  10. #define NOSYSMETRICS
  11. #define NOMENUS
  12. #define NOKEYSTATE
  13. #define NOGDI
  14. #define NORASTEROPS
  15. #define NOSYSCOMMANDS
  16. #define NOSHOWWINDOW
  17. #define NOCOLOR
  18. #define NOATOM
  19. #define NOBITMAP
  20. #define NOICON
  21. #define NOBRUSH
  22. #define NOCREATESTRUCT
  23. #define NOMB
  24. #define NOFONT
  25. #define NOMSG
  26. #define NOOPENFILE
  27. #define NOPEN
  28. #define NOPOINT
  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 "toolbox.h"*/
  38. #include "mw.h"
  39. #include "cmddefs.h"
  40. #include "dispdefs.h"
  41. #include "wwdefs.h"
  42. #include "docdefs.h"
  43. #include "editdefs.h"
  44. #include "filedefs.h"
  45. #include "str.h"
  46. #include "propdefs.h"
  47. #include "fkpdefs.h"
  48. #include "printdef.h" /* printdefs.h */
  49. #include "debug.h"
  50. extern struct DOD (**hpdocdod)[];
  51. extern struct FCB (**hpfnfcb)[];
  52. extern int wwMac;
  53. extern struct WWD rgwwd[];
  54. extern struct WWD *pwwdCur;
  55. extern int **HAllocate();
  56. extern int docCur;
  57. extern typeCP cpMacCur;
  58. extern struct SEL selCur;
  59. extern int ferror;
  60. #ifdef FOOTNOTES
  61. AddFtns(docDest, cpDest, docSrc, cpFirst, cpLim, hfntbSrc)
  62. int docDest, docSrc;
  63. typeCP cpDest, cpFirst, cpLim;
  64. struct FNTB **hfntbSrc;
  65. { /* Add footnote text to coppespond with inserted references */
  66. /* Called after inserting docSrc[cpFirst:cpLim) into docDest@cpDest */
  67. struct FNTB *pfntbSrc, **hfntbDest, *pfntbDest;
  68. struct FND *pfndSrc, *pfndDest;
  69. int cfndDest, ifndSrc, cfndIns, ifndDest;
  70. typeCP cpFtnSrc, dcpFtn, cpFtnDest;
  71. typeCP dcp;
  72. if ((pfndSrc = &(pfntbSrc = *hfntbSrc)->rgfnd[0])->cpFtn <= cpFirst)
  73. return; /* No footnotes or source text is inside ftns */
  74. pfndSrc += (ifndSrc = IcpSearch(cpFirst, pfndSrc,
  75. cchFND, bcpRefFND, pfntbSrc->cfnd));
  76. cpFtnSrc = pfndSrc->cpFtn;
  77. /* Find all references in inserted area. */
  78. for (cfndIns = 0; pfndSrc->cpRef < cpLim; pfndSrc++, cfndIns++)
  79. ;
  80. if (cfndIns != 0)
  81. { /* Insert footnote text and fnd's. */
  82. dcpFtn = pfndSrc->cpFtn - cpFtnSrc; /* Length of ftn texts */
  83. /* Ensure destination fntb large enough */
  84. /* HEAP MOVEMENT */
  85. if (FNoHeap(hfntbDest = HfntbEnsure(docDest, cfndIns)))
  86. return;
  87. if ((pfndDest = &(pfntbDest = *hfntbDest)->rgfnd[0])->cpFtn <= cpDest)
  88. { /* Inserting refs inside footnotes? No way! */
  89. Error(IDPMTFtnLoad);
  90. return;
  91. }
  92. /* Find ifnd to insert new fnd's */
  93. ifndDest = IcpSearch(cpDest, pfndDest,
  94. cchFND, bcpRefFND, cfndDest = pfntbDest->cfnd);
  95. /* Insert new footnote text */
  96. /* HEAP MOVEMENT */
  97. ReplaceCps(docDest, cpFtnDest = (pfndDest + ifndDest)->cpFtn, cp0,
  98. docSrc, cpFtnSrc, dcpFtn);
  99. if (ferror)
  100. return;
  101. /* Insert new fnd's */
  102. pfndSrc = &(pfntbSrc = *hfntbSrc)->rgfnd[ifndSrc];
  103. pfndDest = &(pfntbDest = *hfntbDest)->rgfnd[ifndDest];
  104. pfntbDest->cfnd += cfndIns; /* Update fnd count */
  105. pfndDest->cpFtn += dcpFtn; /* AdjustCp considers the insertion to be
  106. part of this footnote; correct it. */
  107. blt(pfndDest, pfndDest + cfndIns,
  108. cwFND * (cfndDest - ifndDest)); /* Open up fntb */
  109. while (cfndIns--)
  110. { /* Copy fnd's */
  111. pfndDest->cpRef = cpDest + pfndSrc->cpRef - cpFirst;
  112. (pfndDest++)->cpFtn =
  113. cpFtnDest + (pfndSrc++)->cpFtn - cpFtnSrc;
  114. }
  115. /* Invalidate dl's of later ftn refs */
  116. dcp = (**hfntbDest).rgfnd[0].cpFtn - ccpEol - cpDest;
  117. AdjustCp(docDest, cpDest, dcp, dcp);
  118. RecalcWwCps();
  119. }
  120. }
  121. #endif /* FOOTNOTES */
  122. #ifdef FOOTNOTES
  123. /* R E M O V E D E L F T N T E X T */
  124. RemoveDelFtnText(doc, cpFirst, cpLim, hfntb)
  125. int doc;
  126. typeCP cpFirst,cpLim;
  127. struct FNTB **hfntb;
  128. /* Remove the text of footnotes that are contained in the selection that is
  129. delimited by cpFirst and CpLim */
  130. {
  131. struct FNTB *pfntb;
  132. struct FND *pfnd, *pfndT;
  133. int cfnd, ifnd, cfndDel;
  134. if ((pfnd = &(pfntb = *hfntb)->rgfnd[0])->cpFtn > cpFirst)
  135. {
  136. pfnd += (ifnd =
  137. IcpSearch(cpFirst, pfnd, cchFND, bcpRefFND, cfnd = pfntb->cfnd));
  138. /* Find all references in deleted area. */
  139. for (pfndT = pfnd, cfndDel = 0; pfndT->cpRef < cpLim; pfndT++, cfndDel++)
  140. ;
  141. #ifdef DEBUG
  142. Assert(ifnd + cfndDel < cfnd);
  143. #endif
  144. if (cfndDel != 0)
  145. { /* Delete footnote text and close up fntb. */
  146. typeCP cpDel = pfnd->cpFtn;
  147. blt(pfndT, pfnd, cwFND * ((cfnd -= cfndDel) - ifnd));
  148. (*hfntb)->cfnd = cfnd;
  149. /* HEAP MOVEMENT */
  150. Replace(doc, cpDel, pfnd->cpFtn - cpDel, fnNil, fc0, fc0);
  151. if (cfnd == 1)
  152. {
  153. Replace(doc, (**hpdocdod)[doc].cpMac - ccpEol,
  154. (typeCP) ccpEol, fnNil, fc0, fc0);
  155. FreeH((**hpdocdod)[doc].hfntb);
  156. (**hpdocdod)[doc].hfntb = 0;
  157. /* fix selCur twisted by AdjustCp. Another AdjustCp still pending. */
  158. if (doc == docCur && !pwwdCur->fFtn)
  159. {
  160. selCur.cpFirst = selCur.cpLim = cpLim;
  161. cpMacCur = (**hpdocdod)[doc].cpMac;
  162. }
  163. }
  164. else
  165. { /* Invalidate dl's of later ftn refs */
  166. typeCP dcp = (**hfntb).rgfnd[0].cpFtn -
  167. ccpEol - cpLim;
  168. AdjustCp(doc, cpLim, dcp, dcp);
  169. }
  170. }
  171. }
  172. }
  173. #endif /* FOOTNOTES */
  174. #ifdef FOOTNOTES
  175. struct FNTB **HfntbCreate(fn)
  176. int fn;
  177. { /* Create a footnote table from a formatted file */
  178. struct FNTB *pfntbFile;
  179. typePN pn;
  180. int cchT;
  181. int cfnd;
  182. struct FNTB **hfntb;
  183. int *pwFntb;
  184. int cw;
  185. #ifdef DEBUG
  186. Assert(fn != fnNil && (**hpfnfcb)[fn].fFormatted);
  187. #endif
  188. if ((pn = (**hpfnfcb)[fn].pnFntb) == (**hpfnfcb)[fn].pnSep)
  189. return 0;
  190. pfntbFile = (struct FNTB *) PchGetPn(fn, pn, &cchT, false);
  191. if ((cfnd = pfntbFile->cfnd) == 0)
  192. return (struct FNTB **)0;
  193. hfntb = (struct FNTB **) HAllocate(cw = cwFNTBBase + cfnd * cwFND);
  194. if (FNoHeap(hfntb))
  195. return (struct FNTB **)hOverflow;
  196. pwFntb = (int *) *hfntb;
  197. blt(pfntbFile, pwFntb, min(cwSector, cw));
  198. while ((cw -= cwSector) > 0)
  199. { /* Copy the fnd's to heap */
  200. blt(PchGetPn(fn, ++pn, &cchT, false), pwFntb += cwSector,
  201. min(cwSector, cw));
  202. }
  203. (*hfntb)->cfndMax = cfnd;
  204. return hfntb;
  205. }
  206. #endif /* FOOTNOTES */
  207.