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.

873 lines
29 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* NOTE: the routines in this file are not written in a manner which minimizes
  5. code space. It is anticipated that these routines will be swappable
  6. and that a reasonable optimizer will be used when compiling the code */
  7. #define NOCLIPBOARD
  8. #define NOGDICAPMASKS
  9. #define NOCTLMGR
  10. #define NOVIRTUALKEYCODES
  11. #define NOWINMESSAGES
  12. #define NOWINSTYLES
  13. #define NOSYSMETRICS
  14. #define NOMENUS
  15. #define NOKEYSTATE
  16. //#define NOGDI
  17. #define NORASTEROPS
  18. #define NOSYSCOMMANDS
  19. #define NOSHOWWINDOW
  20. #define NOCOLOR
  21. //#define NOATOM
  22. #define NOBITMAP
  23. #define NOICON
  24. #define NOBRUSH
  25. #define NOCREATESTRUCT
  26. #define NOMB
  27. #define NOFONT
  28. #define NOMSG
  29. #define NOOPENFILE
  30. #define NOPEN
  31. #define NOPOINT
  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 "docdefs.h"
  42. #include "editdefs.h"
  43. #include "cmddefs.h"
  44. #include "str.h"
  45. #include "txb.h"
  46. #include "ch.h"
  47. #include "code.h"
  48. #include "wwdefs.h"
  49. #include "printdef.h"
  50. #if defined(OLE)
  51. #include "obj.h"
  52. #endif
  53. #ifndef CASHMERE
  54. #include "propdefs.h"
  55. #endif /* not CASHMERE */
  56. struct UAB vuab;
  57. #ifdef ENABLE
  58. VAL rgvalAgain[ivalMax];
  59. #endif
  60. extern struct WWD *pwwdCur;
  61. extern typeCP cpMacCur;
  62. extern typeCP cpMinCur;
  63. extern int vfSeeSel;
  64. extern int docMac;
  65. extern int docCur;
  66. extern int docScrap;
  67. extern int docUndo;
  68. extern int docBuffer;
  69. extern int vdocPageCache;
  70. extern struct DOD (**hpdocdod)[];
  71. extern struct SEL selCur;
  72. extern CHAR (**hszReplace)[];
  73. extern struct TXB (**hgtxb)[];
  74. /*extern int idstrUndoBase;*/
  75. extern int vfPictSel;
  76. extern int ferror;
  77. extern int docMode;
  78. extern int vfOwnClipboard; /* Whether this instance owns the clip contents */
  79. #ifndef CASHMERE
  80. extern int vdocSectCache;
  81. #endif /* not CASHMERE */
  82. fnUndoEdit()
  83. {
  84. extern HCURSOR vhcIBeam;
  85. StartLongOp();
  86. CmdUndo();
  87. EndLongOp(vhcIBeam);
  88. }
  89. /*
  90. The routines in this file implement the "undo" and "again" features in
  91. Multi-Tool Word. The basic idea is that whenever an editing operation is
  92. about to be done, the global structure "vuab" will be updated to contain
  93. information sufficient to undo or repeat that operation. The structure
  94. (defined in editdefs.h, declared in this file) looks like this:
  95. struct UAB
  96. { UNDO Action Block
  97. int uac; UNDO Action Code (see cmddefs.h)
  98. int doc;
  99. typeCP cp;
  100. typeCP dcp;
  101. int doc2;
  102. typeCP cp2;
  103. typeCP dcp2;
  104. short itxb;
  105. };
  106. Setting up this structure is taken care of by "SetUndo()" which does a lot
  107. of plugging in of values and a couple pseudo-smart things. These smartish
  108. things are:
  109. a) If an insert is made and the last operation was a delete
  110. the two are combined into one "replace" operation.
  111. This means that undo-ing and again-ing apply to the replace and
  112. not just the insertion.
  113. b) When needed (see the code for details) the undo buffer (docUndo)
  114. is filled with any text that needs preservation for future
  115. undo-ing or again-ing. The main example of this is storing away
  116. the old value of the scrap when an operation is about to clobber
  117. the scrap.
  118. Here is a list of the various uac values and what info is stored
  119. other info may be clobbered by the process.
  120. are defined in cmddefs.h. Note that none of the "undo" codes
  121. (those starting with "uacU...") should be set outside of CmdUndo(),
  122. since they may assume things like contents of docUndo which could
  123. be wrong.
  124. Note: This list store information used by the again and undo commands.
  125. Other info may be clobbered by the process.
  126. uacNil No action stored.
  127. uacInsert
  128. doc = document text was inserted into
  129. cp = location at which text was inserted
  130. dcp = length of inserted text
  131. uacUInsert
  132. doc = document from which text was removed (un-inserted)
  133. cp = location at which text was removed
  134. docUndo = text which was removed
  135. uacReplNS
  136. doc = document in which replacement occurred
  137. cp = location at which replacement occurred
  138. dcp = length of inserted text
  139. dcp2 = length of deleted text
  140. docUndo = deleted text
  141. uacUReplNS
  142. doc = document in which replace occrred
  143. cp = location of the replace
  144. dcp = length of re-inserted text
  145. dcp2 = length of un-inserted text
  146. docUndo = un-inserted text
  147. uacReplGlobal
  148. uacChLook
  149. uacChLookSect
  150. uacFormatChar
  151. uacFormatPara
  152. uacFormatSection
  153. uacGalFormatChar
  154. uacGalFormatPara
  155. uacGalFormatSection
  156. uacFormatCStyle
  157. uacFormatPStyle
  158. uacFormatSStyle
  159. uacFormatRHText
  160. uacLookCharMouse
  161. uacLookParaMouse
  162. uacClearAllTab
  163. uacFormatTabs
  164. uacClearTab
  165. uacOvertype
  166. Similar to uacReplNS except that they are agained differently.
  167. uacDelNS
  168. doc = document from which text was deleted
  169. cp = location at which text was deleted
  170. dcp = length of deleted text
  171. docUndo = deleted text
  172. uacUDelNS
  173. doc = document in which text was re-inserted
  174. cp = location at which text was re-inserted
  175. dcp = length of re-inserted text
  176. uacMove
  177. doc = document from which text was deleted
  178. cp = location at which text was deleted
  179. dcp = length of deleted text
  180. (also serves as length of inserted text)
  181. doc2 = document in which text was inserted
  182. cp2 = location at which text was inserted
  183. uacDelScrap
  184. doc = document from which text was deleted
  185. cp = location at which text was deleted
  186. dcp = length of deleted text
  187. docUndo = old contents of scrap
  188. uacUDelScrap
  189. doc = document in which text was re-inserted
  190. cp = location at which text was re-inserted
  191. dcp = length of re-inserted text
  192. uacReplScrap
  193. doc = document in which replacement occurred
  194. cp = location at which replacement occurred
  195. dcp = length of inserted text
  196. docUndo = old contents of scrap
  197. uacUReplScrap
  198. doc = document in which replacement was undone
  199. cp = location at which replacement was undone
  200. dcp = length of re-inserted text
  201. docUndo = deleted text (was originally inserted)
  202. uacDelBuf
  203. doc = document from which text was deleted
  204. cp = location at which text was deleted
  205. cp2 = location in docBuffer of old contents of buffer
  206. dcp2 = size of old contents of buffer
  207. itxb = index of buffer in question
  208. uacUDelBuf
  209. doc = document in which text was re-inserted
  210. cp = location of re-insertion
  211. dcp = amount of text re-inserted
  212. itxb = index of buffer involved
  213. uacReplBuf
  214. doc = document in which replace took place
  215. cp = location of replace
  216. dcp = length of inserted text
  217. cp2 = location of old buffer contents in docBuffer
  218. dcp2 = length of old buffer contents
  219. itxb = index of buffer involved
  220. uacUReplBuf
  221. doc = document in which original replace took place
  222. cp = location of replace
  223. dcp = length of text which was restored in document
  224. itxb = index of buffer involved
  225. docUndo = un-inserted text
  226. uacCopyBuf
  227. cp = location of old buffer contents in docBuffer
  228. dcp = length of old buffer contents
  229. itxb = index of buffer involved
  230. uacUCopyBuf
  231. cp = location of undone buffer contents in docBuffer
  232. dcp = length of undone buffer contents
  233. itxb = index of buffer involved
  234. */
  235. CmdUndo()
  236. { /* UNDO */
  237. typeCP dcpT,cpT,dcpT2;
  238. int docT;
  239. int f;
  240. struct DOD *pdod, *pdodUndo;
  241. int uac;
  242. #ifndef CASHMERE
  243. struct SEP **hsep;
  244. struct TBD (**hgtbd)[];
  245. struct PGTB **hpgtb;
  246. struct PGTB **hpgtbUndo;
  247. struct PGTB **hpgtbT;
  248. BOOL near FCopyPgtb(int, struct PGTB ***);
  249. #endif /* not CASHMERE */
  250. TurnOffSel();
  251. ClearInsertLine();
  252. switch (uac = vuab.uac)
  253. {
  254. struct TXB *ptxb;
  255. default:/* case uacNil: */
  256. Assert(false); /* Won't get here cause menu should be greyed */
  257. return;
  258. case uacInsert:
  259. case uacInsertFtn:
  260. case uacUDelNS:
  261. ClobberDoc(docUndo, vuab.doc, vuab.cp, vuab.dcp);
  262. Replace(vuab.doc, vuab.cp, vuab.dcp, fnNil, fc0, fc0);
  263. dcpT = cp0;
  264. vuab.uac = (uac == uacUDelNS) ? uacDelNS : uacUInsert;
  265. /* idstrUndoBase = uac == uacUDelNS ? IDSTRUndoBase : IDSTRUndoRedo;*/
  266. SetUndoMenuStr(IDSTRUndoBase);
  267. if (uac == uacInsertFtn)
  268. TrashAllWws(); /* Simple, but effective */
  269. break;
  270. case uacUInsert:
  271. case uacDelNS:
  272. ReplaceCps(vuab.doc, vuab.cp, cp0, docUndo, cp0, dcpT = vuab.dcp);
  273. vuab.uac = (uac == uacUInsert) ? uacInsert : uacUDelNS;
  274. /* idstrUndoBase = uac == uacUInsert ? IDSTRUndoBase : IDSTRUndoRedo;*/
  275. SetUndoMenuStr(IDSTRUndoBase);
  276. break;
  277. case uacDelScrap: /* UNDO CUT */
  278. if ( !vfOwnClipboard )
  279. ferror = TRUE;
  280. else
  281. {
  282. ReplaceCps(vuab.doc, vuab.cp, cp0, docScrap, cp0,
  283. dcpT = CpMacText(docScrap));
  284. vuab.uac = uacUDelScrap;
  285. /* idstrUndoBase = IDSTRUndoRedo;*/
  286. SetUndoMenuStr(IDSTRUndoBase);
  287. ClobberDoc( docScrap, docUndo, cp0, CpMacText( docUndo ) );
  288. ChangeClipboard();
  289. }
  290. break;
  291. case uacUDelScrap: /* REDO CUT */
  292. ClobberDoc( docUndo, docScrap, cp0, CpMacText( docScrap ) );
  293. /* idstrUndoBase = IDSTRUndoBase;*/
  294. SetUndoMenuStr(IDSTRUndoBase);
  295. vuab.uac = uacDelScrap;
  296. ClobberDoc(docScrap, vuab.doc, vuab.cp, vuab.dcp);
  297. Replace(vuab.doc, vuab.cp, vuab.dcp, fnNil, fc0, fc0);
  298. ChangeClipboard();
  299. dcpT = 0;
  300. break;
  301. case uacReplScrap: /* UNDO COPY */
  302. if (!vfOwnClipboard)
  303. ferror = TRUE;
  304. else
  305. {
  306. dcpT = CpMacText(docScrap);
  307. ReplaceCps(vuab.doc, vuab.cp + vuab.dcp, cp0,
  308. docScrap, cp0, dcpT);
  309. ClobberDoc( docScrap, docUndo, cp0, CpMacText( docUndo ) );
  310. /* idstrUndoBase = IDSTRUndoRedo;*/
  311. SetUndoMenuStr(IDSTRUndoBase);
  312. vuab.uac = uacUReplScrap;
  313. ClobberDoc(docUndo, vuab.doc, vuab.cp, vuab.dcp);
  314. Replace(vuab.doc, vuab.cp, vuab.dcp, fnNil, fc0, fc0);
  315. vuab.dcp = dcpT;
  316. ChangeClipboard();
  317. }
  318. break;
  319. case uacUReplScrap: /* REDO COPY */
  320. dcpT = CpMacText(docUndo);
  321. ReplaceCps(vuab.doc, vuab.cp + vuab.dcp, cp0,
  322. docUndo, cp0, dcpT);
  323. ClobberDoc( docUndo, docScrap, cp0, CpMacText( docScrap ));
  324. /* idstrUndoBase = IDSTRUndoBase;*/
  325. SetUndoMenuStr(IDSTRUndoBase);
  326. vuab.uac = uacReplScrap;
  327. ClobberDoc(docScrap, vuab.doc, vuab.cp, vuab.dcp);
  328. Replace(vuab.doc, vuab.cp, vuab.dcp, fnNil, fc0, fc0);
  329. vuab.dcp = dcpT;
  330. ChangeClipboard();
  331. break;
  332. #ifdef DEBUG
  333. case uacUCopyBuf:
  334. case uacCopyBuf:
  335. case uacUReplBuf:
  336. case uacReplBuf:
  337. case uacUDelBuf:
  338. case uacDelBuf:
  339. Assert( FALSE ); /* No buffers in MEMO */
  340. #ifdef ENABLE
  341. DoUndoTxb(); /* Moved to txb.c */
  342. #endif
  343. break;
  344. #endif /* DEBUG */
  345. case uacMove:
  346. if (!FMoveText(vuab.doc2, vuab.cp2, vuab.dcp, vuab.doc, &vuab.cp, fFalse))
  347. return;
  348. dcpT = vuab.dcp;
  349. cpT = vuab.cp;
  350. vuab.cp = vuab.cp2;
  351. vuab.cp2 = cpT;
  352. docT = vuab.doc;
  353. vuab.doc = vuab.doc2;
  354. vuab.doc2 = docT;
  355. CheckMove();
  356. break;
  357. case uacUReplNS:
  358. case uacChLook:
  359. case uacChLookSect:
  360. case uacReplNS:
  361. case uacFormatChar:
  362. case uacFormatPara:
  363. case uacGalFormatChar:
  364. case uacGalFormatPara:
  365. case uacGalFormatSection:
  366. case uacReplGlobal:
  367. case uacFormatCStyle:
  368. case uacFormatPStyle:
  369. case uacFormatSStyle:
  370. case uacFormatRHText:
  371. case uacLookCharMouse:
  372. case uacLookParaMouse:
  373. case uacClearAllTab:
  374. case uacClearTab:
  375. case uacOvertype:
  376. #ifdef CASHMERE
  377. case uacFormatTabs:
  378. case uacFormatSection:
  379. #endif /* CASHMERE */
  380. #ifdef BOGUS
  381. /* Must do insertion first, in front, in case footnote */
  382. /* if (uac == uacOvertype)
  383. vuab.dcp2 = CpMin(vuab.dcp, vuab.dcp2);*/
  384. dcpT = vuab.dcp2;
  385. ReplaceCps(vuab.doc, vuab.cp, cp0, docUndo, cp0, dcpT);
  386. ClobberDoc(docUndo, vuab.doc, vuab.cp + dcpT, vuab.dcp);
  387. Replace(vuab.doc, vuab.cp + dcpT, vuab.dcp, fnNil, fc0, fc0);
  388. vuab.dcp2 = vuab.dcp;
  389. vuab.dcp = dcpT;
  390. if(uac == uacReplNS)
  391. vuab.uac = uacUReplNS;
  392. else if(uac == uacUReplNS)
  393. vuab.uac = uacReplNS;
  394. /* idstrUndoBase = uac != uacUReplNS ? IDSTRUndoRedo : IDSTRUndoBase;*/
  395. SetUndoMenuStr(IDSTRUndoBase);
  396. break;
  397. #endif
  398. case uacReplPic:
  399. case uacUReplPic:
  400. case uacPictSel:
  401. dcpT = uac != uacPictSel ? vuab.dcp2 : vuab.dcp;
  402. ReplaceCps(docUndo, dcpT, cp0, vuab.doc, vuab.cp, vuab.dcp);
  403. ReplaceCps(vuab.doc, vuab.cp, vuab.dcp, docUndo, cp0, dcpT);
  404. Replace(docUndo, cp0, dcpT, fnNil, fc0, fc0);
  405. if (uac != uacPictSel)
  406. {
  407. vuab.dcp2 = vuab.dcp;
  408. vuab.dcp = dcpT;
  409. }
  410. if (uac == uacPictSel)
  411. {
  412. dcpT = (**hpdocdod)[vuab.doc].cpMac - vuab.cp;
  413. AdjustCp(vuab.doc, vuab.cp, dcpT, dcpT);
  414. }
  415. if(uac == uacReplPic)
  416. vuab.uac = uacUReplPic;
  417. else if(uac == uacUReplPic)
  418. vuab.uac = uacReplPic;
  419. else if(uac == uacReplNS)
  420. vuab.uac = uacUReplNS;
  421. else if(uac == uacUReplNS)
  422. vuab.uac = uacReplNS;
  423. /* switch(uac) */
  424. /* { */
  425. /* case uacUReplPic: */
  426. /* case uacUReplNS: */
  427. /* idstrUndoBase = IDSTRUndoBase; */
  428. /* break; */
  429. /* case uacReplPic: */
  430. /* case uacReplNS: */
  431. /* idstrUndoBase = IDSTRUndoRedo; */
  432. /* break; */
  433. /* default: */
  434. /* idstrUndoBase = (idstrUndoBase == */
  435. /* IDSTRUndoRedo) ? IDSTRUndoBase : IDSTRUndoRedo;*/
  436. /* break; */
  437. /* } */
  438. /*--- idstrUndoBase = (uac != uacUReplPic && uac != uacUReplNS) ?
  439. IDSTRUndoRedo : IDSTRUndoBase;---*/
  440. SetUndoMenuStr(IDSTRUndoBase);
  441. Select( CpFirstSty( selCur.cpFirst, styChar ),
  442. CpLastStyChar( selCur.cpLim ) );
  443. break;
  444. #ifndef CASHMERE
  445. case uacRepaginate:
  446. /* Make a copy of the document's page table. */
  447. if (!FCopyPgtb(vuab.doc, &hpgtb) || !FCopyPgtb(docUndo, &hpgtbUndo))
  448. {
  449. break;
  450. }
  451. /* Swap the contents of the entire document with docUndo. */
  452. dcpT = CpMacText(vuab.doc);
  453. dcpT2 = CpMacText(docUndo);
  454. ReplaceCps(docUndo, dcpT2, cp0, vuab.doc, cp0, dcpT);
  455. ReplaceCps(vuab.doc, cp0, dcpT, docUndo, cp0, dcpT2);
  456. Replace(docUndo, cp0, dcpT2, fnNil, fc0, fc0);
  457. /* Swap the page tables of the two documents. */
  458. if ((hpgtbT = (**hpdocdod)[vuab.doc].hpgtb) != NULL)
  459. {
  460. FreeH(hpgtbT);
  461. }
  462. (**hpdocdod)[vuab.doc].hpgtb = hpgtbUndo;
  463. if ((hpgtbT = (**hpdocdod)[docUndo].hpgtb) != NULL)
  464. {
  465. FreeH(hpgtbT);
  466. }
  467. (**hpdocdod)[docUndo].hpgtb = hpgtb;
  468. vdocPageCache = docNil;
  469. break;
  470. case uacFormatSection:
  471. pdod = &(**hpdocdod)[vuab.doc];
  472. pdodUndo = &(**hpdocdod)[docUndo];
  473. hsep = pdod->hsep;
  474. pdod->hsep = pdodUndo->hsep;
  475. pdodUndo->hsep = hsep;
  476. hpgtb = pdod->hpgtb;
  477. pdod->hpgtb = pdodUndo->hpgtb;
  478. pdodUndo->hpgtb = hpgtb;
  479. /* idstrUndoBase = (idstrUndoBase == IDSTRUndoRedo) ? IDSTRUndoBase :*/
  480. /* IDSTRUndoRedo;*/
  481. SetUndoMenuStr(IDSTRUndoBase);
  482. vdocSectCache = vdocPageCache = docMode = docNil;
  483. TrashAllWws();
  484. break;
  485. case uacRulerChange:
  486. ReplaceCps(docUndo, vuab.dcp2, cp0, vuab.doc, vuab.cp, vuab.dcp);
  487. ReplaceCps(vuab.doc, vuab.cp, vuab.dcp, docUndo, cp0, vuab.dcp2);
  488. Replace(docUndo, cp0, vuab.dcp2, fnNil, fc0, fc0);
  489. dcpT = vuab.dcp;
  490. vuab.dcp = vuab.dcp2;
  491. vuab.dcp2 = dcpT;
  492. /* This is a kludge to indicate that this is an undone ruler change.
  493. */
  494. vuab.itxb = 1 - vuab.itxb;
  495. case uacFormatTabs:
  496. pdod = &(**hpdocdod)[vuab.doc];
  497. pdodUndo = &(**hpdocdod)[docUndo];
  498. hgtbd = pdod->hgtbd;
  499. pdod->hgtbd = pdodUndo->hgtbd;
  500. pdodUndo->hgtbd = hgtbd;
  501. /* idstrUndoBase = (idstrUndoBase == IDSTRUndoRedo) ? IDSTRUndoBase :*/
  502. /* IDSTRUndoRedo;*/
  503. SetUndoMenuStr(IDSTRUndoBase);
  504. TrashAllWws();
  505. break;
  506. #endif /* not CASHMERE */
  507. #if UPDATE_UNDO
  508. #if defined(OLE)
  509. case uacObjUpdate:
  510. case uacUObjUpdate:
  511. ObjDoUpdateUndo(vuab.doc,vuab.cp);
  512. if (uac == uacObjUpdate)
  513. {
  514. vuab.uac = uacUObjUpdate;
  515. SetUndoMenuStr(IDSTRUndoBase);
  516. }
  517. break;
  518. #endif
  519. #endif
  520. }
  521. if (ferror)
  522. NoUndo();
  523. pdod = &(**hpdocdod)[vuab.doc];
  524. pdodUndo = &(**hpdocdod)[docUndo];
  525. f = pdod->fDirty;
  526. pdod->fDirty = pdodUndo->fDirty;
  527. pdodUndo->fDirty = f;
  528. f = pdod->fFormatted;
  529. pdod->fFormatted = pdodUndo->fFormatted;
  530. pdodUndo->fFormatted = f;
  531. #ifdef CASHMERE
  532. if (uac != uacMove
  533. #else /* not CASHMERE */
  534. if (uac != uacMove && uac != uacFormatTabs && uac != uacFormatSection &&
  535. uac != uacRulerChange
  536. #endif /* not CASHMERE */
  537. && docCur != docNil && vuab.doc == docCur && vuab.cp >= cpMinCur &&
  538. vuab.cp + dcpT <= cpMacCur)
  539. {
  540. if (uac == uacPictSel)
  541. {
  542. Select(vuab.cp, CpLimSty(vuab.cp, styPara));
  543. vfPictSel = true;
  544. }
  545. else
  546. #ifdef BOGUS
  547. Select( vuab.cp,
  548. (dcpT == cp0) ? CpLastStyChar( vuab.cp ) :
  549. vuab.cp + dcpT );
  550. #endif
  551. Select( vuab.cp, vuab.cp + dcpT );
  552. vfSeeSel = true;
  553. }
  554. }
  555. BOOL near FCopyPgtb(doc, phpgtb)
  556. int doc;
  557. struct PGTB ***phpgtb;
  558. {
  559. /* This sets *phpgtb to a copy of the page table associated with doc. FALSE
  560. is returned iff an error occurs in creating the copy of the page table. */
  561. struct PGTB **hpgtbT;
  562. if ((hpgtbT = (**hpdocdod)[doc].hpgtb) == NULL)
  563. {
  564. *phpgtb = NULL;
  565. }
  566. else
  567. {
  568. int cwpgtb = cwPgtbBase + (**hpgtbT).cpgdMax * cwPGD;
  569. if (FNoHeap(*phpgtb = (struct PGTB **)HAllocate(cwpgtb)))
  570. {
  571. return (FALSE);
  572. }
  573. blt(*hpgtbT, **phpgtb, cwpgtb);
  574. }
  575. return (TRUE);
  576. }
  577. #ifdef CASHMERE /* No Repeat-last-command in MEMO */
  578. CmdAgain()
  579. { /* use the undo action block to repeat a command */
  580. int uac;
  581. typeCP dcpT;
  582. typeCP cpFirst;
  583. typeCP cpLim;
  584. typeCP dcp;
  585. struct DOD *pdod, *pdodUndo;
  586. /* First check error conditions; this may change selCur */
  587. switch (uac = vuab.uac)
  588. {
  589. case uacReplBuf:
  590. case uacUReplBuf:
  591. case uacDelBuf:
  592. case uacUDelBuf:
  593. case uacUDelNS:
  594. case uacDelNS:
  595. case uacUDelScrap:
  596. case uacDelScrap:
  597. case uacUReplNS:
  598. case uacOvertype:
  599. case uacReplNS:
  600. case uacReplGlobal:
  601. case uacReplScrap:
  602. case uacUReplScrap:
  603. /* Ensure OK to delete here */
  604. if (!FWriteOk(fwcDelete))
  605. return;
  606. break;
  607. case uacUCopyBuf:
  608. case uacCopyBuf:
  609. if (false)
  610. return;
  611. break;
  612. case uacUInsert:
  613. case uacInsert:
  614. if (!FWriteOk(fwcInsert))
  615. return;
  616. break;
  617. case uacMove:
  618. /* Ensure OK to edit here */
  619. if (!FWriteOk(fwcInsert))
  620. return;
  621. break;
  622. default:
  623. break;
  624. }
  625. /* Now set up cp's and dispatch */
  626. cpFirst = selCur.cpFirst;
  627. cpLim = selCur.cpLim;
  628. dcp = cpLim - cpFirst;
  629. switch (uac = vuab.uac)
  630. {
  631. struct TXB *ptxb;
  632. default:
  633. /* case uacNil: */
  634. _beep();
  635. return;
  636. #ifdef ENABLE /* NO GLOSSARY IN MEMO */
  637. case uacReplBuf:
  638. case uacUReplBuf:
  639. case uacDelBuf:
  640. case uacUDelBuf:
  641. case uacUCopyBuf:
  642. case uacCopyBuf:
  643. DoAgainTxb(dcp, cpFirst);
  644. break;
  645. #endif /* ENABLE */
  646. case uacUInsert:
  647. ReplaceCps(docCur, cpFirst, cp0, docUndo, cp0, vuab.dcp);
  648. vuab.doc = docCur;
  649. vuab.cp = cpFirst;
  650. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst+vuab.dcp));
  651. vuab.uac = uacInsert;
  652. break;
  653. case uacInsert:
  654. ClobberDoc(docUndo, vuab.doc, vuab.cp, vuab.dcp);
  655. ReplaceCps(docCur, cpFirst, cp0, docUndo, cp0, vuab.dcp);
  656. vuab.doc = docCur;
  657. vuab.cp = cpFirst;
  658. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst+vuab.dcp));
  659. break;
  660. case uacUDelNS:
  661. case uacDelNS:
  662. ClobberDoc(docUndo, docCur, cpFirst, dcp);
  663. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  664. vuab.doc = docCur;
  665. vuab.cp = cpFirst;
  666. vuab.dcp = dcp;
  667. vuab.uac = uacDelNS;
  668. Select(cpFirst,CpLastStyChar(cpFirst));
  669. break;
  670. case uacUDelScrap:
  671. case uacDelScrap:
  672. ClobberDoc(docUndo,docScrap,cp0,CpMacText(docScrap));
  673. ClobberDoc(docScrap, docCur, cpFirst, dcp);
  674. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  675. vuab.doc = docCur;
  676. vuab.cp = cpFirst;
  677. vuab.dcp = dcp;
  678. vuab.uac = uacDelScrap;
  679. Select(cpFirst, CpLastStyChar(cpFirst));
  680. break;
  681. case uacUReplNS:
  682. vuab.dcp2 = vuab.dcp;
  683. ReplaceCps(docCur, cpLim, cp0, docUndo, cp0,
  684. vuab.dcp = CpMacText(docUndo));
  685. ClobberDoc(docUndo, docCur, cpFirst, dcp);
  686. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  687. vuab.doc = docCur;
  688. vuab.cp = cpFirst;
  689. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst + vuab.dcp));
  690. vuab.uac = uacReplNS;
  691. break;
  692. case uacOvertype:
  693. /* for this one vuab.cp2 is the DCP of how much was actually
  694. inserted */
  695. vuab.dcp = vuab.cp2;
  696. /* fall through...*/
  697. case uacReplNS:
  698. ClobberDoc(docUndo, vuab.doc, vuab.cp, vuab.dcp);
  699. ReplaceCps(docCur, cpLim, cp0, docUndo, cp0, vuab.dcp);
  700. ClobberDoc(docUndo, docCur, cpFirst, dcp);
  701. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  702. dcpT = vuab.dcp;
  703. vuab.dcp2 = dcp;
  704. vuab.doc = docCur;
  705. vuab.cp = cpFirst;
  706. vuab.uac = uacReplNS;
  707. if (ferror) /* the operation (cmd "a") could not be completed
  708. due to out of memory */
  709. NoUndo();
  710. else
  711. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst + dcpT));
  712. break;
  713. case uacChLook:
  714. case uacChLookSect:
  715. #ifdef ENABLE /* ChLook stuff is not hooked up yet */
  716. DoChLook(chAgain,0);
  717. #endif
  718. break;
  719. case uacReplGlobal:
  720. ClobberDoc(docUndo, docCur, cpFirst, dcp);
  721. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  722. vuab.dcp2 = dcp;
  723. dcp = (typeCP)(CchSz(**hszReplace) - 1);
  724. InsertRgch(docCur, cpFirst, **hszReplace, dcp, 0, 0);
  725. vuab.dcp = dcp;
  726. vuab.doc = docCur;
  727. vuab.cp = cpFirst;
  728. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst + vuab.dcp));
  729. vuab.uac = uacReplNS;
  730. break;
  731. case uacReplScrap:
  732. ClobberDoc(docUndo, vuab.doc, vuab.cp, vuab.dcp);
  733. ReplaceCps(docCur, cpLim, cp0, docUndo, cp0, vuab.dcp);
  734. ClobberDoc(docUndo,docScrap,cp0,CpMacText(docScrap));
  735. ClobberDoc(docScrap, docCur, cpFirst, dcp);
  736. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  737. vuab.doc = docCur;
  738. vuab.cp = cpFirst;
  739. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst + vuab.dcp));
  740. break;
  741. #ifdef ENABLE /* Not used in SAND */
  742. case uacFormatCStyle:
  743. DoFormatCStyle(rgvalAgain);
  744. break;
  745. case uacFormatPStyle:
  746. DoFormatPStyle(rgvalAgain);
  747. break;
  748. case uacFormatSStyle:
  749. DoFormatSStyle(rgvalAgain);
  750. break;
  751. #endif /* ENABLE */
  752. #ifdef ENABLE /* Not hooked up yet */
  753. case uacLookCharMouse:
  754. AgainLookCharMouse();
  755. break;
  756. case uacLookParaMouse:
  757. AgainLookParaMouse();
  758. break;
  759. #endif /* ENABLE */
  760. #ifdef ENABLE /* Not used in SAND */
  761. case uacClearTab:
  762. DoClearTab(true);
  763. vuab.uac = uac;
  764. break;
  765. case uacClearAllTab:
  766. CmdClearAllTab();
  767. vuab.uac = uac;
  768. break;
  769. #endif /* ENABLE */
  770. #ifdef ENABLE /* Formatting menu stuff is not hooked up yet */
  771. case uacFormatTabs:
  772. DoFormatTabs(true);
  773. vuab.uac = uac;
  774. break;
  775. case uacFormatRHText:
  776. DoFormatRHText(rgvalAgain);
  777. break;
  778. case uacFormatChar:
  779. DoFormatChar(rgvalAgain);
  780. break;
  781. case uacFormatPara:
  782. DoFormatPara(rgvalAgain);
  783. break;
  784. case uacFormatSection:
  785. DoFormatSection(rgvalAgain);
  786. break;
  787. #endif /* ENABLE */
  788. #ifdef STYLES
  789. case uacGalFormatChar:
  790. DoGalFormatChar(rgvalAgain);
  791. break;
  792. case uacGalFormatPara:
  793. DoGalFormatPara(rgvalAgain);
  794. break;
  795. case uacGalFormatSection:
  796. DoGalFormatSection(rgvalAgain);
  797. break;
  798. #endif /* STYLES */
  799. case uacUReplScrap:
  800. ReplaceCps(docCur, cpLim, cp0, docUndo, cp0,
  801. vuab.dcp = CpMacText(docUndo));
  802. ClobberDoc(docUndo,docScrap,cp0,CpMacText(docScrap));
  803. ClobberDoc(docScrap, docCur, cpFirst, dcp);
  804. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  805. vuab.doc = docCur;
  806. vuab.cp = cpFirst;
  807. Select(cpFirst+vuab.dcp, CpLastStyChar(cpFirst + vuab.dcp));
  808. vuab.uac = uacReplScrap;
  809. break;
  810. case uacMove:
  811. if (!FMoveText(vuab.doc2, vuab.cp2, vuab.dcp, docCur, &cpFirst, fFalse))
  812. return;
  813. vuab.cp = vuab.cp2;
  814. vuab.cp2 = cpFirst;
  815. vuab.doc = vuab.doc2;
  816. vuab.doc2 = docCur;
  817. CheckMove();
  818. break;
  819. }
  820. vfSeeSel = true;
  821. }
  822. #endif /* CASHMERE */
  823. 
  824.