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.

450 lines
12 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 NORECT
  30. #define NOREGION
  31. #define NOSCROLL
  32. #define NOSOUND
  33. #define NOWH
  34. #define NOWINOFFSETS
  35. #define NOWNDCLASS
  36. #define NOCOMM
  37. #include <windows.h>
  38. #include "mw.h"
  39. #include "code.h"
  40. #include "txb.h"
  41. #include "str.h"
  42. #include "docdefs.h"
  43. #include "cmddefs.h"
  44. #include "filedefs.h"
  45. #include "ch.h"
  46. #include "propdefs.h"
  47. #include "fmtdefs.h"
  48. #include "dispdefs.h"
  49. #include "stcdefs.h"
  50. /*#include "toolbox.h"*/
  51. #include "wwdefs.h"
  52. /* New functionality for Sand: Jan 17, 1984
  53. Kenneth J. Shapiro */
  54. /*---------------------------------------------------------------------------
  55. The following routines form the interface between the buffer code and the
  56. rest of multi-word:
  57. CmdXfBufClear() - used by "Transfer Buffer Clear"
  58. CmdXfBufLoad() - used by "Transfer Buffer Load"
  59. CmdXfBufSave() - used by "Transfer Buffer Save"
  60. ----------------------------------------------------------------------------*/
  61. /*---------------------------------------------------------------------------
  62. External global references:
  63. ----------------------------------------------------------------------------*/
  64. extern int vfSeeSel;
  65. extern struct DOD (**hpdocdod)[];
  66. extern VAL rgval[];
  67. extern int docCur;
  68. extern struct SEL selCur;
  69. extern int YCOCMD;
  70. extern typeCP cpMacCur;
  71. extern int docScrap;
  72. /*extern WINDOWPTR ActiveWindow;
  73. extern WINDOWPTR windowGlos;
  74. */
  75. extern CHAR stBuf[];
  76. extern struct WWD *pwwdCur;
  77. extern struct TXB (**hgtxb)[]; /* array of txbs. Sorted for binary search */
  78. extern short itxbMac; /* indicates current size of hgtxb */
  79. extern int docBuffer; /* doc containing all buffer text */
  80. extern int vfBuffersDirty;
  81. extern int rfnMac;
  82. extern struct ERFN dnrfn[];
  83. #ifdef ENABLE
  84. /*---------------------------------------------------------------------------
  85. -- Routine: CmdXfBufClear()
  86. -- Description and Usage:
  87. Called by the menu routines to execute "Transfer Buffer Clear"
  88. rgval[0] contains a list of buffer names, stored in an hsz.
  89. The list is just as the user typed it.
  90. Makes the user confirm the action, and then removes all of the named
  91. buffers. If no buffers are named, it clear ALL buffers.
  92. -- Arguments: none
  93. -- Returns: nothing
  94. -- Side-effects:
  95. Clears some subset of the named buffers.
  96. -- Bugs:
  97. -- History:
  98. 3/25/83 - created (tsr)
  99. 4/27/83 - modified to handle list of names (tsr)
  100. ----------------------------------------------------------------------------*/
  101. CmdXfBufClear()
  102. {
  103. #ifdef DEMOA
  104. DemoErr();
  105. #else
  106. int ich;
  107. int itxb;
  108. if(!cnfrm(IDPMTBufCnfrm))
  109. return;
  110. NoUndo();
  111. if(CchSz(**(CHAR(**)[])rgval[0])==1)
  112. {
  113. for(itxb=0; itxb < itxbMac ; itxb++)
  114. {
  115. FreeH((**hgtxb)[itxb].hszName);
  116. }
  117. FreeH(hgtxb);
  118. hgtxb = HAllocate(cwTxb);
  119. #ifdef DEBUG
  120. /* We just freed the space, so it shouldn't be bad now */
  121. Assert(!FNoHeap(hgtxb));
  122. #endif /*DEBUG*/
  123. (**hgtxb)[0].hszName = hszNil;
  124. itxbMac = 0;
  125. KillDoc(docBuffer);
  126. docBuffer = DocCreate(fnNil, (CHAR (**)[]) 0, dtyBuffer);
  127. }
  128. else
  129. FClearBuffers(**(CHAR(**)[])rgval[0], CchSz(**(CHAR(**)[])rgval[0])-1,
  130. TRUE, &ich);
  131. #endif /* DEMOA */
  132. }
  133. #endif /* ENABLE */
  134. #ifdef ENABLE
  135. /*---------------------------------------------------------------------------
  136. -- Routine: CmdXfBufLoad()
  137. -- Description and Usage:
  138. Called by the menu routines to execute "Transfer Buffer Load"
  139. rgval[0] contains the name of the file to load.
  140. Merges references to the loaded buffers into the buffer list stored in
  141. hgtxb. Requires additions to docBuffer for each newly one.
  142. -- Arguments: none
  143. -- Returns: nothing
  144. -- Side-effects:
  145. Can define/clobber many buffers.
  146. -- Bugs:
  147. -- History:
  148. 3/22/83 - created (tsr)
  149. ----------------------------------------------------------------------------*/
  150. CmdXfBufLoad()
  151. {
  152. #ifdef DEMOA
  153. DemoErr();
  154. #else
  155. extern CHAR (**hszGlosFile)[];
  156. /* for each buffer definition in the file:
  157. a) add the related text to the end of docBuffer
  158. b) insert or replace the reference for that buffer name
  159. */
  160. CHAR (**hszFile)[] = (CHAR (**)[]) rgval[0];
  161. int fn;
  162. if ((fn = FnOpenSz(**hszFile, dtyBuffer, TRUE)) == fnNil)
  163. {
  164. Error(IDPMTBadFile);
  165. return;
  166. }
  167. NoUndo();
  168. MergeTxbsFn(fn);
  169. if ((**hszGlosFile)[0] == 0)
  170. {
  171. FreeH(hszGlosFile);
  172. hszGlosFile = hszFile;
  173. }
  174. vfBuffersDirty = true;
  175. #endif /* DEMOA */
  176. }
  177. #endif /* ENABLE */
  178. #ifdef ENABLE
  179. /*---------------------------------------------------------------------------
  180. -- Routine: MergeTxbsFn(fn)
  181. -- Description and Usage:
  182. Given an fn which contains a buffer document, this function reads in
  183. the text of the file, appending it to docBuffer. It also reads
  184. the Bftb from the file in order to build the appropriate mapping
  185. from buffer name to text.
  186. -- Arguments:
  187. fn - file containing buffer definitions.
  188. -- Returns:
  189. nothing
  190. -- Side-effects:
  191. builds new buffers onto docBuffer and hgtxb
  192. -- Bugs:
  193. -- History:
  194. 3/24/83 - created (tsr)
  195. ----------------------------------------------------------------------------*/
  196. MergeTxbsFn(fn)
  197. int fn;
  198. {
  199. extern struct FCB (**hpfnfcb)[];
  200. extern short ItxbFromHsz();
  201. unsigned pbftbFile;
  202. typePN pn;
  203. int cchT;
  204. CHAR (**hbftb)[];
  205. int *pwBftb;
  206. int cw;
  207. int ich;
  208. short itxbNew;
  209. struct TXB *ptxbNew;
  210. typeCP cp, dcp;
  211. typeCP cpBufMac;
  212. CHAR(**hszNew)[];
  213. int docNew;
  214. CHAR sz[cchMaxSz];
  215. #ifdef DEBUG
  216. Assert(fn != fnNil && (**hpfnfcb)[fn].fFormatted);
  217. #endif
  218. if ((pn = (**hpfnfcb)[fn].pnBftb) ==(**hpfnfcb)[fn].pnFfntb)
  219. return;
  220. pbftbFile = (unsigned) PchGetPn(fn, pn, &cchT, false);
  221. hbftb = (CHAR (**) []) HAllocate(cw=((**hpfnfcb)[fn].pnFfntb - (**hpfnfcb)[fn].pnBftb)*cwSector);
  222. if (FNoHeap((int)hbftb))
  223. return;
  224. pwBftb = *(int **)hbftb;
  225. blt(pbftbFile, pwBftb, min(cwSector, cw));
  226. while ((cw -= cwSector) > 0)
  227. { /* Copy the records to heap */
  228. blt(PchGetPn(fn, ++pn, &cchT, false), pwBftb += cwSector,
  229. min(cwSector, cw));
  230. }
  231. ich = 0;
  232. cp = cp0;
  233. cpBufMac = CpMacText(docBuffer);
  234. bltsz(**(**hpfnfcb)[fn].hszFile, sz);
  235. docNew = DocCreate(fn, HszCreate(sz), dtyBuffer); /* HEAP MOVES */
  236. while((**hbftb)[ich] != '\0')
  237. {
  238. bltsz(&(**hbftb)[ich], sz);
  239. sz[cchMaxSz - 1] = 0;
  240. hszNew = (CHAR(**)[]) HszCreate(sz); /*** HEAP MOVES ***/
  241. ich += CchSz(sz);
  242. bltbyte(&(**hbftb)[ich], &dcp, sizeof(typeCP));
  243. ich += sizeof(typeCP);
  244. itxbNew = ItxbFromHsz(hszNew);
  245. #ifdef DEBUG
  246. Assert(itxbNew >= 0);
  247. #endif /* DEBUG */
  248. ReplaceCps(docBuffer, cpBufMac, cp0, docNew, cp, dcp); /*HEAP MOVES*/
  249. ptxbNew = &(**hgtxb)[itxbNew];
  250. ptxbNew->cp=cpBufMac;
  251. ptxbNew->dcp=dcp;
  252. cpBufMac += dcp;
  253. cp += dcp;
  254. }
  255. KillDoc(docNew);
  256. FreeH((int **)hbftb);
  257. }
  258. #endif /* ENABLE */
  259. #ifdef ENABLE
  260. /*---------------------------------------------------------------------------
  261. -- Routine: CmdXfBufSave()
  262. -- Description and Usage:
  263. Called by the menu routines to execute "Transfer Buffer Save"
  264. rgval[0] contains the name of the file to save the buffers in.
  265. Creates a single doc to contain all of the buffers and updates
  266. hgtxb to reference that doc, cleaning up all of the temporary
  267. docs that were around.
  268. Stores that doc in the file, putting a table at the end of the file
  269. which maps buffer names to locations within the file.
  270. -- Arguments: none
  271. -- Returns: nothing
  272. -- Side-effects:
  273. -- Bugs:
  274. -- History:
  275. 3/22/83 - created (tsr)
  276. ----------------------------------------------------------------------------*/
  277. CmdXfBufSave(szFile)
  278. CHAR szFile[];
  279. {
  280. #ifndef WDEMO
  281. CHAR (**hszFile)[];
  282. CHAR szBak[cchMaxFile];
  283. long ltype;
  284. /* Move file name to local */
  285. /* bltbyte(**hszFile, szFile, cchMaxFile);*/
  286. BackupSzFile(szFile, true, szBak, &ltype);
  287. /* ForcePmt(IDPMTSaving);*/
  288. NoUndo();
  289. #ifdef STYLES
  290. (**hpdocdod)[docBuffer].docSsht = (**hpdocdod)[docCur].docSsht;
  291. #endif
  292. CachePara(docBuffer, cp0);
  293. CleanDoc(docBuffer, szFile, true, true);
  294. (**hpdocdod)[docBuffer].docSsht = docNil;
  295. if (!FNoHeap(hszFile = HszCreate(szFile)))
  296. {
  297. FreeH(hszGlosFile);
  298. hszGlosFile = hszFile;
  299. }
  300. vfBuffersDirty = false;
  301. #endif /* not WDEMO */
  302. }
  303. #endif /* ENABLE */
  304. #ifdef ENABLE
  305. /*---------------------------------------------------------------------------
  306. -- Routine: CleanBuffers()
  307. -- Description and Usage:
  308. Creates a new docBuffer containing only currently referenced buffer text.
  309. This is to keep old buffer values from lying around through
  310. eternity.
  311. -- Arguments: none
  312. -- Returns: nothing
  313. -- Side-effects:
  314. creates a new doc for docBuffer.
  315. kills old docBuffer.
  316. -- Bugs:
  317. -- History:
  318. 3/24/83 - create (tsr)
  319. ----------------------------------------------------------------------------*/
  320. CleanBuffers()
  321. {
  322. #ifdef DEMOA
  323. #else
  324. int docNew;
  325. short itxb;
  326. struct TXB *ptxb;
  327. typeCP cp, cpOld;
  328. typeCP dcp;
  329. docNew = DocCreate(fnNil, (CHAR (**)[]) 0, dtyBuffer);
  330. for(cp=0, itxb=0;itxb<itxbMac;itxb++, cp+=dcp)
  331. {
  332. ptxb = &(**hgtxb)[itxb];
  333. cpOld = ptxb->cp;
  334. ptxb->cp = cp;
  335. /* HEAP MOVEMENT */
  336. ReplaceCps(docNew, cp, cp0, docBuffer, cpOld, dcp = ptxb->dcp);
  337. }
  338. KillDoc(docBuffer);
  339. docBuffer = docNew;
  340. NoUndo();
  341. #endif /* DEMOA */
  342. }
  343. #endif /* ENABLE */
  344. /*---------------------------------------------------------------------------
  345. -- Routine: WriteBftb(fn)
  346. -- Description and Usage:
  347. Given an fn for a buffer file that is being written, this routine
  348. actually writes out the Bftb which maps buffer names to pieces of
  349. text stored in the file.
  350. -- Arguments:
  351. fn - file being written.
  352. -- Returns: nothing
  353. -- Side-effects:
  354. Writes to the file described by fn.
  355. -- Bugs:
  356. -- History:
  357. 3/24/83 - created (tsr)
  358. ----------------------------------------------------------------------------*/
  359. WriteBftb(fn)
  360. int fn;
  361. {
  362. #ifdef DEMOA
  363. #else
  364. short itxb;
  365. struct TXB *ptxb;
  366. for(itxb = 0 ; itxb < itxbMac ; itxb ++ )
  367. {
  368. ptxb = &(**hgtxb)[itxb];
  369. WriteRgch(fn, &(**(ptxb->hszName))[0], CchSz(**(ptxb->hszName)));
  370. ptxb = &(**hgtxb)[itxb];
  371. WriteRgch(fn, (CHAR *)&(ptxb->dcp), sizeof(typeCP));
  372. }
  373. WriteRgch(fn, "", sizeof(CHAR));
  374. #endif /* DEMOA */
  375. }
  376. #ifdef ENABLE
  377. int CchCurGlosFile(pfld, pch, fNew, ival)
  378. struct fld *pfld;
  379. CHAR *pch;
  380. int fNew, ival;
  381. {
  382. int cch;
  383. extern CHAR (**hszGlosFile)[];
  384. CleanBuffers();
  385. CloseEveryRfnTB(true);
  386. if((cch = CchSz(**hszGlosFile)-1) == 0)
  387. cch = CchFillSzId(pch, IDSTRGLYN);
  388. else
  389. bltbyte(**hszGlosFile, pch, cch);
  390. return(cch);
  391. }
  392. #endif /* ENABLE */
  393. #ifdef ENABLE
  394. /* F N N E W F I L E */
  395. ClearGlosBuf ()
  396. {
  397. rgval[0] = HszCreate("");
  398. CmdXfBufClear();
  399. RecreateListbox(cidstrRsvd + itxbMac);
  400. return;
  401. }
  402. #endif /* ENABLE */
  403. #ifdef ENABLE
  404. CloseEveryRfnTB(fRetry)
  405. int fRetry;
  406. {
  407. int rfn;
  408. for(rfn = 0; rfn < rfnMac; rfn++)
  409. {
  410. if(dnrfn[rfn].fn != fnNil)
  411. CloseRfn( rfn );
  412. }
  413. }
  414. #endif /* ENABLE */
  415.