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.

432 lines
14 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* AddPrm.c -- Routines to add prms and sprms to docs */
  5. #define NOGDICAPMASKS
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINMESSAGES
  8. #define NOWINSTYLES
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #define NOKEYSTATE
  12. #define NOSYSCOMMANDS
  13. #define NORASTEROPS
  14. #define NOSHOWWINDOW
  15. #define NOSYSMETRICS
  16. #define NOATOM
  17. #define NOBITMAP
  18. #define NOBRUSH
  19. #define NOPEN
  20. #define NOCLIPBOARD
  21. #define NOCOLOR
  22. #define NOCTLMGR
  23. #define NOWNDCLASS
  24. #define NODRAWTEXT
  25. #define NOFONT
  26. #define NOGDI
  27. #define NOHDC
  28. #define NOMB
  29. #define NOMENUS
  30. #define NOMETAFILE
  31. #define NOMSG
  32. #define NOTEXTMETRIC
  33. #define NOSOUND
  34. #define NOSCROLL
  35. #define NOCOMM
  36. /* no everything except MEMMGR */
  37. #include <windows.h>
  38. #include "mw.h"
  39. #include "cmddefs.h"
  40. #include "code.h"
  41. #include "ch.h"
  42. #include "docdefs.h"
  43. #include "editdefs.h"
  44. #include "str.h"
  45. #include "prmdefs.h"
  46. #include "propdefs.h"
  47. #include "filedefs.h"
  48. #include "stcdefs.h"
  49. #include "fkpdefs.h"
  50. #include "macro.h"
  51. #include "dispdefs.h"
  52. /* E X T E R N A L S */
  53. extern int docCur;
  54. extern struct SEL selCur;
  55. extern struct DOD (**hpdocdod)[];
  56. extern struct UAB vuab;
  57. extern int vfSysFull;
  58. extern CHAR dnsprm[];
  59. extern struct CHP vchpSel;
  60. extern typeCP vcpLimParaCache;
  61. extern typeCP cpMacCur;
  62. extern typeCP CpLimNoSpaces();
  63. extern int ferror;
  64. /* G L O B A L S */
  65. struct FPRM fprmCache = { 0 };
  66. struct PRM prmCache = {0,0,0,0};
  67. /* A D D O N E S P R M */
  68. /* applies sprm at psprm to the current selection. Take care of
  69. undoing, invalidation, special endmark cases, and extension of selection
  70. to paragraph boundaries */
  71. void AddOneSprm(psprm, fSetUndo)
  72. CHAR *psprm;
  73. int fSetUndo; /* True if we need to set up the undo buffer */
  74. {
  75. int cch;
  76. int fParaSprm = fFalse;
  77. typeCP cpFirst, cpLim, dcp;
  78. if (!FWriteOk( fwcNil ))
  79. return;
  80. if ((dnsprm[*psprm] & ESPRM_sgc) != sgcChar)
  81. {
  82. typeCP dcpExtraPara = cp0;
  83. cpFirst = CpFirstSty( selCur.cpFirst, styPara );
  84. CachePara( docCur, CpMax( selCur.cpLim - 1, selCur.cpFirst ) );
  85. cpLim = vcpLimParaCache;
  86. dcp = cpLim - cpFirst;
  87. /* Check for para following selection that has no Eol */
  88. if (cpLim < cpMacCur)
  89. {
  90. /* Note that in this case only, dcp (the # of cp's affected
  91. by the change) does not equal (cpLim - cpFirst)
  92. (the # of cp's to which the sprm should apply) */
  93. CachePara( docCur, cpLim );
  94. dcpExtraPara = vcpLimParaCache - cpLim;
  95. }
  96. if (cpFirst + dcp + dcpExtraPara > cpMacCur)
  97. { /* Last para affected has no Eol -- add one */
  98. struct SEL selSave;
  99. dcp += dcpExtraPara;
  100. Assert( cpFirst + dcp == cpMacCur + (typeCP) ccpEol);
  101. if (fSetUndo)
  102. {
  103. SetUndo( uacReplNS, docCur, cpFirst, dcp,
  104. docNil, cpNil, dcp - ccpEol, 0 );
  105. fSetUndo = fFalse;
  106. }
  107. /* Add an eol. Save the current selection so
  108. it does not get adjusted */
  109. selSave = selCur;
  110. InsertEolInsert(docCur,cpMacCur);
  111. selCur = selSave;
  112. }
  113. }
  114. else
  115. { /* Char sprm -- eliminate trailing spaces from the
  116. affected region, so we don't underline spaces after words. */
  117. cpFirst = selCur.cpFirst;
  118. cpLim = CpLimNoSpaces(selCur.cpFirst, selCur.cpLim);
  119. dcp = cpLim - cpFirst;
  120. if (dcp == 0)
  121. { /* Doing character looks to the insert point... */
  122. if (fSetUndo)
  123. SetUndo(uacReplNS, docCur, cpFirst, cp0,
  124. docNil, cp0, cp0, 0);
  125. DoSprm(&vchpSel, 0, *psprm, psprm + 1);
  126. return;
  127. }
  128. }
  129. if (fSetUndo)
  130. SetUndo(uacReplNS, docCur, cpFirst, dcp, docNil, cpNil, dcp, 0);
  131. if (ferror) /* not enough memory to store info for undo operation */
  132. {
  133. NoUndo();
  134. return;
  135. }
  136. AddSprmCps(psprm, docCur, cpFirst, cpLim);
  137. AdjustCp( docCur, cpFirst, dcp, dcp );
  138. }
  139. /* E X P A N D C U R S E L */
  140. ExpandCurSel(pselSave)
  141. struct SEL *pselSave;
  142. {
  143. *pselSave = selCur;
  144. selCur.cpFirst = CpFirstSty(selCur.cpFirst, styPara);
  145. CachePara(docCur, CpMax(selCur.cpLim - 1, selCur.cpFirst));
  146. selCur.cpLim = vcpLimParaCache;
  147. }
  148. /* E N D L O O K S E L */
  149. EndLookSel(pselSave, fPara)
  150. struct SEL *pselSave; BOOL fPara;
  151. {
  152. typeCP cpLim, cpFirst, dcp;
  153. dcp = (cpLim = selCur.cpLim) - (cpFirst = selCur.cpFirst);
  154. if (fPara)
  155. {
  156. TrashCache();
  157. if (cpLim <= cpMacCur)
  158. {
  159. CachePara(docCur, selCur.cpLim);
  160. if (vcpLimParaCache > cpMacCur) /* Last (partial) paragraph */
  161. dcp = cpMacCur - cpFirst + 1;
  162. }
  163. }
  164. AdjustCp(docCur, cpFirst, dcp, dcp);
  165. selCur = *pselSave;
  166. }
  167. /* A D D S P R M */
  168. AddSprm(psprm)
  169. CHAR *psprm;
  170. { /* Add a single property modifier to the pieces contained in selCur. */
  171. AddSprmCps(psprm, docCur, selCur.cpFirst, selCur.cpLim);
  172. }
  173. /* A D D S P R M C P S */
  174. AddSprmCps(char *psprm, int doc, typeCP cpFirst, typeCP cpLim)
  175. {
  176. struct PCTB **hpctb;
  177. int ipcdFirst, ipcdLim, ipcd;
  178. struct DOD *pdod;
  179. int cch;
  180. struct PCD *ppcd;
  181. /* First get address of piece table and split off desired pieces. */
  182. pdod = &(**hpdocdod)[doc];
  183. hpctb = pdod->hpctb;
  184. pdod->fFormatted = fTrue;
  185. ipcdFirst = IpcdSplit(hpctb, cpFirst);
  186. ipcdLim = IpcdSplit(hpctb, cpLim);
  187. if (ferror)
  188. /* Ran out of memory trying to expand piece table */
  189. return;
  190. /* Now just add this sprm to the pieces. */
  191. FreezeHp();
  192. for (ipcd = ipcdFirst, ppcd = &(**hpctb).rgpcd[ipcdFirst];
  193. ipcd < ipcdLim && !vfSysFull; ++ipcd, ++ppcd)
  194. ppcd->prm = PrmAppend(ppcd->prm, psprm);
  195. MeltHp();
  196. }
  197. /* P R M A P P E N D */
  198. struct PRM PrmAppend(struct PRM prm, CHAR *psprm)
  199. { /* Append <sprm, val> to the chain of sprm's in prm. Return new prm. */
  200. struct FPRM *pfprmOld;
  201. CHAR *pfsprm;
  202. CHAR *pfsprmOld;
  203. int sprm = *psprm;
  204. int sprmOld;
  205. register int esprm = dnsprm[sprm];
  206. register int esprmOld;
  207. int cchNew = (esprm & ESPRM_cch);
  208. int cchOld;
  209. int sgc = (esprm & ESPRM_sgc);
  210. int spr = (esprm & ESPRM_spr);
  211. int fSame = (esprm & ESPRM_fSame);
  212. int fClobber = (esprm & ESPRM_fClobber);
  213. int dval = 0;
  214. int cch;
  215. int cchT;
  216. typeFC fcPrm;
  217. struct FPRM fprm;
  218. if (cchNew == 0) cchNew = CchPsprm(psprm);
  219. pfsprm = fprm.grpfsprm;
  220. if (prm.fComplex)
  221. { /* Get the old list of sprm's from scratch file; copy it to fprm. */
  222. pfprmOld = (struct FPRM *) PchFromFc(fnScratch,
  223. //(typeFC)(unsigned)(((struct PRMX *) &prm)->bfprm << 1), &cch);
  224. fcSCRATCHPRM(prm), &cch);
  225. pfsprmOld = pfprmOld->grpfsprm;
  226. cchT = cch = pfprmOld->cch;
  227. while (cchT)
  228. { /* Copy grpsprm, removing ones which we will clobber */
  229. sprmOld = *pfsprmOld;
  230. esprmOld = dnsprm[sprmOld];
  231. if ((cchOld = (esprmOld & ESPRM_cch)) == 0)
  232. cchOld = CchPsprm(pfsprmOld);
  233. #ifdef DEBUG
  234. if (cchOld == 0)
  235. panic();
  236. #endif
  237. if (sprmOld == sprm && fSame ||
  238. (esprmOld & ESPRM_sgc) == sgc &&
  239. (esprmOld & ESPRM_spr) <= spr && fClobber)
  240. {
  241. /* make sure we properly coalesce change
  242. size prms */
  243. if (sprm == sprmOld && sprm == sprmCChgHps)
  244. dval += *(pfsprmOld + 1);
  245. cch -= cchOld;
  246. }
  247. /* CHps overrides CChgHps */
  248. else if (sprmOld == sprmCChgHps && sprm == sprmCHps)
  249. {
  250. cch -= cchOld;
  251. }
  252. else
  253. pfsprm = (CHAR *)bltbyte(pfsprmOld, pfsprm, cchOld);
  254. pfsprmOld += cchOld;
  255. cchT -= cchOld;
  256. }
  257. }
  258. else
  259. { /* No file entry yet; convert simple prm to fsprm */
  260. int valOld = prm.val;
  261. sprmOld = prm.sprm;
  262. esprmOld = dnsprm[sprmOld];
  263. if (bPRMNIL(prm) ||
  264. sprmOld == sprm && fSame ||
  265. (esprmOld & ESPRM_sgc) == sgc &&
  266. (esprmOld & ESPRM_spr) <= spr && fClobber)
  267. {
  268. /* make sure we are combinning consecutive sprmCChgHps */
  269. if (sprm == sprmOld && sprm == sprmCChgHps)
  270. dval += valOld;
  271. cch = 0;
  272. }
  273. /* CHps overrides CChgHps */
  274. else if (sprmOld == sprmCChgHps && sprm == sprmCHps)
  275. {
  276. cch = 0;
  277. }
  278. else
  279. { /* Save old sprm */
  280. *pfsprm++ = sprmOld;
  281. if ((cch = (esprmOld & ESPRM_cch)) == 2)
  282. *pfsprm++ = valOld;
  283. }
  284. }
  285. /* we have: cch = length of old prm after removal of clobbered/etc. entries.
  286. cchNew: length of the entry to be appended.
  287. dval: correction for 2nd byte of new entry
  288. pfsprm: where 1st byte of new entry will go
  289. */
  290. bltbyte((CHAR *) psprm, pfsprm, imin(cchNew, cchMaxGrpfsprm - cch));
  291. *(pfsprm + 1) += dval;
  292. if (cch == 0 && cchNew <= 2)
  293. { /* Pack sprm and val into a prm word. */
  294. struct PRM prmT;
  295. prmT.dummy=0;
  296. bltbyte(pfsprm, (CHAR *) &prmT, cchNew);
  297. prmT.fComplex = false;
  298. prmT.sprm = *pfsprm;
  299. return (prmT);
  300. }
  301. if ((cch += cchNew) > cchMaxGrpfsprm)
  302. {
  303. int fSave = ferror;
  304. Error(IDPMT2Complex);
  305. ferror = fSave;
  306. return (prm);
  307. }
  308. if (vfSysFull)
  309. return prm; /* Assume disk full message already given */
  310. fprm.cch = cch;
  311. /* Check newly created prm to see if same as previous */
  312. if (CchDiffer(&fprmCache, &fprm, cch + 1) == 0)
  313. return prmCache;
  314. bltbyte(&fprm, &fprmCache, cch + 1);
  315. AlignFn(fnScratch, cch = ((cch >> 1) + 1) << 1, fTrue);
  316. prm.fComplex = fTrue;
  317. //((struct PRMX)prm).bfprm = FcWScratch((CHAR *) &fprm, cch) >> 1;
  318. fcPrm = FcWScratch((CHAR *) &fprm, cch) >> 1;
  319. ((struct PRMX *)&prm)->bfprm_hi = (fcPrm >> 16) & 0x7F;
  320. ((struct PRMX *)&prm)->bfprm_low = fcPrm & 0xFFFF;
  321. prmCache = prm;
  322. return prm;
  323. }
  324. /* A P P L Y C L O O K S */
  325. /* character looks. val is a 1 char value */
  326. ApplyCLooks(pchp, sprm, val)
  327. struct CHP *pchp;
  328. int sprm, val;
  329. {
  330. /* Assemble sprm */
  331. CHAR rgbSprm[1 + cchINT];
  332. CHAR *pch = &rgbSprm[0];
  333. *pch++ = sprm;
  334. *pch = val;
  335. if (pchp == 0)
  336. {
  337. /* apply looks to current selection */
  338. AddOneSprm(rgbSprm, fTrue);
  339. vuab.uac = uacChLook;
  340. SetUndoMenuStr(IDSTRUndoLook);
  341. }
  342. else
  343. {
  344. /* apply looks to pchp */
  345. DoSprm(pchp, 0, sprm, pch);
  346. }
  347. }
  348. /* A P P L Y L O O K S P A R A S */
  349. /* val is a char value */
  350. ApplyLooksParaS(pchp, sprm, val)
  351. struct CHP *pchp;
  352. int sprm, val;
  353. {
  354. int valT = 0;
  355. CHAR *pch = (CHAR *)&valT;
  356. *pch = val;
  357. /* all the above is just to prepare bltbyte later gets the right byte order */
  358. ApplyLooksPara(pchp, sprm, valT);
  359. }
  360. /* A P P L Y L O O K S P A R A */
  361. /* val is an integer value. Char val's must have been bltbyte'd into val */
  362. ApplyLooksPara(pchp, sprm, val)
  363. struct CHP *pchp;
  364. int sprm, val;
  365. {
  366. if (FWriteOk(fwcNil)) /* Check for out-of-memory/ read-only */
  367. {
  368. CHAR rgbSprm[1 + cchINT];
  369. CHAR *pch = &rgbSprm[0];
  370. *pch++ = sprm;
  371. bltbyte(&val, pch, cchINT);
  372. AddOneSprm(rgbSprm, fTrue);
  373. vuab.uac = uacChLook;
  374. SetUndoMenuStr(IDSTRUndoLook);
  375. }
  376. }
  377.