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.

278 lines
7.8 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOVIRTUALKEYCODES
  5. #define NOWINSTYLES
  6. #define NOCTLMGR
  7. #define NOWINMESSAGES
  8. #define NOGDICAPMASKS
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #include "windows.h"
  12. #include "mw.h"
  13. #include "cmddefs.h"
  14. #include "fmtdefs.h"
  15. #include "docdefs.h"
  16. #include "propdefs.h"
  17. #include "prmdefs.h"
  18. #include "editdefs.h"
  19. #include "macro.h"
  20. #include "str.h"
  21. #if defined(OLE)
  22. #include "obj.h"
  23. #endif
  24. /* E X T E R N A L S */
  25. extern int vstyCur;
  26. extern int docCur;
  27. extern typeCP vcpLimParaCache;
  28. extern struct SEL selCur;
  29. extern struct PAP vpapAbs;
  30. extern struct SEL selPend;
  31. extern struct UAB vuab;
  32. extern struct CHP vchpFetch;
  33. extern struct CHP vchpSel;
  34. extern int docUndo;
  35. extern int ferror;
  36. extern typeCP cpMinCur;
  37. extern typeCP cpMacCur;
  38. extern int vfObjSel;
  39. /* L O O K S M O U S E */
  40. LooksMouse()
  41. {
  42. int cch;
  43. char rgb[cchPAP + 2];
  44. if (vstyCur == styPara || vstyCur == styLine)
  45. { /* Copy paragraph looks */
  46. /* MEMO Version: no effect on tab table */
  47. int itbd;
  48. CachePara(docCur, selCur.cpFirst);
  49. #ifdef CASHMERE
  50. for (itbd = 0; vpapAbs.rgtbd[itbd].dxa != 0; itbd++);
  51. rgb[1] = (cwPAPBase + (itbd + 1) * cwTBD) * cchINT;
  52. bltbyte(&vpapAbs, &rgb[2], rgb[1]);
  53. #else
  54. blt( &vpapAbs, &rgb[2], rgb[1] = cwPAPBase );
  55. #endif
  56. rgb[0] = sprmPSame;
  57. Select(selPend.cpFirst, selPend.cpLim);
  58. AddOneSprm(rgb, fTrue);
  59. vuab.uac = uacLookParaMouse;
  60. }
  61. else
  62. { /* Copy character looks */
  63. struct CHP chpT;
  64. FetchCp(docCur, CpMax(cp0, selCur.cpFirst - 1), 0, fcmProps);
  65. chpT = vchpFetch;
  66. Select(selPend.cpFirst, selPend.cpLim);
  67. vchpSel = chpT;
  68. if (selPend.cpFirst == selPend.cpLim)
  69. return;
  70. bltbyte(&vchpSel, &rgb[1], cwCHP * cchINT);
  71. rgb[0] = sprmCSame;
  72. AddOneSprm(rgb, fTrue);
  73. vuab.uac = uacLookCharMouse;
  74. }
  75. SetUndoMenuStr(IDSTRUndoLook);
  76. }
  77. /* C O P Y M O U S E */
  78. CopyMouse()
  79. {
  80. typeCP cpDest, cpSrc, dcp;
  81. int fKludge = false;
  82. if (selPend.cpFirst == selPend.cpLim)
  83. return;
  84. if (FWriteOk(fwcInsert))
  85. {
  86. cpDest = selCur.cpFirst;
  87. dcp = selPend.cpLim - (cpSrc = selPend.cpFirst);
  88. /*----- SetUndo(uacInsert, docCur, cpDest, dcp, docNil, cpNil, cp0, 0);--*/
  89. /* ReplaceCps can't deal with copies from/to the same doc, so use undo
  90. buffer as intermediate storage */
  91. NoUndo();
  92. ClobberDoc(docUndo, docCur, cpSrc, dcp);
  93. if (ferror)
  94. return;
  95. else if (!FCheckPicture(&cpDest, dcp, true, docCur))
  96. SetUndo(uacInsert, docCur, cpDest, dcp, docNil, cpNil, cp0, 0);
  97. ReplaceCps(docCur, cpDest, cp0, docUndo, cp0, dcp);
  98. if (ferror)
  99. {
  100. NoUndo();
  101. return;
  102. }
  103. else
  104. {
  105. #if defined(OLE)
  106. ObjEnumInRange(docCur,cpDest,cpDest+dcp,ObjCloneObjectInDoc);
  107. #endif
  108. if (cpDest >= cpMinCur && cpDest + dcp <= cpMacCur)
  109. Select(cpDest, cpDest + dcp);
  110. }
  111. }
  112. SetUndoMenuStr(IDSTRUndoEdit);
  113. }
  114. /* M O V E M O U S E */
  115. MoveMouse()
  116. {
  117. typeCP cpSrc, dcp, cpDest;
  118. if (selPend.cpFirst == selPend.cpLim)
  119. return;
  120. if (FWriteOk(fwcInsert))
  121. {
  122. cpDest = selCur.cpFirst;
  123. dcp = selPend.cpLim - (cpSrc = selPend.cpFirst);
  124. if (FMoveText(docCur, cpSrc, dcp, docCur, &cpDest, fTrue))
  125. SetUndoMenuStr(IDSTRUndoEdit);
  126. }
  127. }
  128. /* F M O V E T E X T */
  129. int FMoveText(docSrc, cpSrc, dcp, docDest, pcpDest, fSetUndo)
  130. int docSrc, docDest, fSetUndo;
  131. typeCP cpSrc, dcp, *pcpDest;
  132. { /* returns true unless moving into yourself */
  133. int fT;
  134. typeCP cpT, cpMacT;
  135. Assert(docSrc == docDest);
  136. /* Same document; use undo buffer as intermediary */
  137. if (*pcpDest >= cpSrc && *pcpDest < cpSrc + dcp
  138. #ifdef FOOTNOTES
  139. || *pcpDest >= CpFirstFtn(docSrc, cpSrc, &fT) &&
  140. *pcpDest < CpFirstFtn(docSrc, cpSrc + dcp, &fT)
  141. #endif
  142. )
  143. {
  144. Error(IDPMTBadMove);
  145. return false;
  146. }
  147. ClobberDoc(docUndo, docSrc, cpSrc, dcp);
  148. if (ferror)
  149. return false;
  150. if (FCheckPicture(pcpDest, dcp, false, docDest))
  151. if (cpSrc >= *pcpDest)
  152. cpSrc += (typeCP)ccpEol;
  153. /* cpMacT will measure the total adjustment incurred by the following replace
  154. as it may be different from dcp-cp0 (e.g. due to Eol inserted in front of
  155. a picture
  156. */
  157. cpMacT = cpMacCur;
  158. ReplaceCps(docDest, *pcpDest, cp0, docUndo, cp0, dcp);
  159. cpT = *pcpDest;
  160. if (docDest == docSrc)
  161. {
  162. if (cpT < cpSrc)
  163. cpSrc += cpMacCur - cpMacT;
  164. else /* cpT >= cpSrc */
  165. cpT -= cpMacCur - cpMacT;
  166. }
  167. /* Now delete old text */
  168. Replace(docSrc, cpSrc, dcp, fnNil, fc0, fc0);
  169. if (ferror)
  170. {
  171. NoUndo();
  172. return FALSE;
  173. }
  174. else
  175. {
  176. if (docDest == docCur && cpT >= cpMinCur && cpT + dcp <= cpMacCur)
  177. Select(cpT, cpT + dcp);
  178. if (fSetUndo)
  179. SetUndo(uacMove, docCur, cpSrc, dcp, docCur, cpT, cp0, 0);
  180. }
  181. return true;
  182. }
  183. /* F C H E C K P I C T U R E */
  184. int FCheckPicture(pcpDest, dcp, fSetUndo, doc)
  185. typeCP *pcpDest, dcp;
  186. int fSetUndo;
  187. int doc;
  188. {
  189. typeCP cpDest = *pcpDest;
  190. CachePara(docUndo, cp0);
  191. if (vpapAbs.fGraphics && cpDest > cp0)
  192. { /* Special case for inserting a picture paragraph */
  193. CachePara(doc, cpDest - 1);
  194. if (vcpLimParaCache == cpDest + 1 && vcpLimParaCache < cpMacCur)
  195. /* this special case is here to move the insertion point from 1 char away
  196. from a para boundary (a common point to select) to the boundary so that
  197. we do not have to insert an ugly extra cr. This does not apply at the
  198. end of the document */
  199. {
  200. *pcpDest += 1;
  201. return fFalse;
  202. }
  203. if (vcpLimParaCache != cpDest)
  204. {
  205. if (fSetUndo)
  206. SetUndo(uacInsert, doc, cpDest, dcp + (typeCP)ccpEol,
  207. docNil, cpNil, cp0, 0);
  208. InsertEolPap(doc, cpDest, &vpapAbs);
  209. *pcpDest += (typeCP)ccpEol;
  210. return true;
  211. }
  212. }
  213. return false;
  214. }
  215. /* C H E C K M O V E */
  216. CheckMove()
  217. {
  218. if(vuab.doc == vuab.doc2)
  219. {
  220. /* same doc means we might have to worry about shifting cp's */
  221. if (vuab.cp < vuab.cp2)
  222. vuab.cp2 -= vuab.dcp;
  223. else if (vuab.cp > vuab.cp2)
  224. vuab.cp += vuab.dcp;
  225. #ifdef DEBUG
  226. else
  227. Assert(false);
  228. #endif
  229. }
  230. }
  231.