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.

295 lines
6.2 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* Select2.c -- Less-frequently-used selection routines */
  5. #define NOCLIPBOARD
  6. #define NOGDICAPMASKS
  7. #define NOCTLMGR
  8. #define NOVIRTUALKEYCODES
  9. #define NOWINMESSAGES
  10. #define NOWINSTYLES
  11. #define NOSYSMETRICS
  12. #define NOMENUS
  13. #define NOSOUND
  14. #define NOCOMM
  15. #define NOPEN
  16. #define NOWNDCLASS
  17. #define NOICON
  18. #define NORASTEROPS
  19. #define NOSHOWWINDOW
  20. #define NOATOM
  21. #define NOKEYSTATE
  22. #define NOSYSCOMMANDS
  23. #define NOBITMAP
  24. #define NOBRUSH
  25. #define NOCOLOR
  26. #define NODRAWTEXT
  27. #define NOMB
  28. #define NOPOINT
  29. #define NOMSG
  30. #include <windows.h>
  31. #include "mw.h"
  32. #include "toolbox.h"
  33. #include "docdefs.h"
  34. #include "editdefs.h"
  35. #include "dispdefs.h"
  36. #include "cmddefs.h"
  37. #include "wwdefs.h"
  38. #include "ch.h"
  39. #include "fmtdefs.h"
  40. #include "propdefs.h"
  41. extern int vfSeeSel;
  42. extern typeCP vcpFirstParaCache;
  43. extern typeCP vcpLimParaCache;
  44. extern typeCP vcpFetch;
  45. extern CHAR *vpchFetch;
  46. extern int vccpFetch;
  47. extern typeCP cpMinCur;
  48. extern typeCP cpMacCur;
  49. extern struct SEL selCur;
  50. extern int docCur;
  51. extern struct FLI vfli;
  52. extern struct WWD rgwwd[];
  53. extern int vfSelHidden;
  54. extern int wwCur;
  55. extern struct CHP vchpFetch;
  56. extern struct PAP vpapAbs;
  57. extern struct WWD *pwwdCur;
  58. extern int vfInsEnd;
  59. extern typeCP CpBeginLine();
  60. extern int vfPictSel;
  61. extern int vfSizeMode;
  62. extern struct CHP vchpNormal;
  63. extern int vfInsertOn;
  64. extern struct CHP vchpSel; /* Holds the props when the selection
  65. is an insert point */
  66. extern int vfMakeInsEnd;
  67. extern typeCP vcpSelect;
  68. extern int vfSelAtPara;
  69. /* true iff the last selection was made by an Up/Down cursor key */
  70. extern int vfLastCursor;
  71. /* C P L I M S T Y S P E C I A L */
  72. typeCP CpLimStySpecial(cp, sty)
  73. typeCP cp;
  74. int sty;
  75. { /* Return the first cp which is not part of the same sty unit */
  76. int wb, ch, ich;
  77. struct EDL *pedl;
  78. /* Other cases covered in CpLimSty, our only caller */
  79. Assert( cp < cpMacCur );
  80. Assert( cp >= cpMinCur );
  81. Assert( sty == styWord || sty == stySent );
  82. /* Special kludge for picture paragraphs */
  83. CachePara(docCur, cp);
  84. if (vpapAbs.fGraphics)
  85. return vcpLimParaCache;
  86. FetchCp(docCur, cp, 0, fcmChars + fcmNoExpand);
  87. Assert(vccpFetch != 0);
  88. /* Must be word or sentence */
  89. wb = WbFromCh(ch = vpchFetch[ich = 0]);
  90. #ifdef CRLF
  91. if (ch == chReturn)
  92. return vcpFetch + 2;
  93. #endif
  94. if (ch == chEol || ch == chSect || ch == chNewLine || ch == chTab)
  95. /* EOL is its own unit */
  96. return vcpFetch + 1;
  97. if (wb == wbWhite && sty == stySent)
  98. { /* Might be between sentences; go back to text */
  99. FetchCp(docCur, CpFirstSty(cp, styWord), 0, fcmChars + fcmNoExpand);
  100. wb = WbFromCh(ch = vpchFetch[ich = 0]);
  101. }
  102. for (;;)
  103. {
  104. if (++ich >= vccpFetch)
  105. { /* Get next line and set up */
  106. FetchCp(docNil, cpNil, 0, fcmChars);
  107. if (vcpFetch == cpMacCur)
  108. return cpMacCur; /* End of doc */
  109. ich = 0;
  110. }
  111. if (sty == stySent)
  112. switch (ch)
  113. {
  114. case chDot:
  115. case chBang:
  116. case chQMark:
  117. sty = styWord;
  118. wb = wbPunct;
  119. }
  120. switch (ch = vpchFetch[ich])
  121. {
  122. case chTab:
  123. case chEol:
  124. case chSect:
  125. case chNewLine:
  126. #ifdef CRLF
  127. case chReturn:
  128. #endif
  129. goto BreakFor;
  130. }
  131. if (sty == styWord)
  132. { /* Word ends after white space or on text/punct break */
  133. int wbT = WbFromCh(ch);
  134. if (wb != wbT && (wb = wbT) != wbWhite)
  135. break;
  136. }
  137. }
  138. BreakFor:
  139. return vcpFetch + ich;
  140. }
  141. /* C P F I R S T S T Y S P E C I A L */
  142. typeCP CpFirstStySpecial(cp, sty)
  143. typeCP cp;
  144. int sty;
  145. { /* Return the first cp of this sty unit. */
  146. typeCP cpBegin;
  147. int wb, ch, dcpChunk;
  148. typeCP cpSent;
  149. CHAR rgch[dcpAvgSent];
  150. int ich;
  151. typeCP cpT;
  152. /* Other cases were covered by CpFirstSty, our only caller */
  153. Assert( cp > cpMinCur );
  154. Assert( sty == stySent || sty == styWord );
  155. if (cp >= cpMacCur)
  156. cpT = cp = cpMacCur;
  157. else
  158. cpT = cp++;
  159. CachePara(docCur, cpT );
  160. if ((vcpFirstParaCache == cpT) || vpapAbs.fGraphics)
  161. return vcpFirstParaCache;
  162. dcpChunk = (sty == styWord) ? dcpAvgWord : dcpAvgSent;
  163. cpBegin = (cp > dcpChunk) ? cp - dcpChunk : cp0;
  164. FetchRgch(&ich, rgch, docCur, cpBegin, cp, dcpChunk);
  165. wb = WbFromCh(ch = rgch[--ich]);
  166. #ifdef CRLF
  167. if(cpBegin + ich == 0)
  168. return cp0;
  169. if (ch == chEol && rgch[ich-1] == chReturn) /* EOL is its own unit */
  170. return cpBegin + ich - 1;
  171. if (ch == chEol || ch == chReturn || ch == chSect || ch == chNewLine || ch == chTab)
  172. return cpBegin + ich;
  173. #else /* not CRLF */
  174. if (ch == chEol || ch == chSect || ch == chNewLine || ch == chTab) /* EOL is its own unit */
  175. return cpBegin + ich;
  176. #endif /* CRLF */
  177. if (wb == wbText)
  178. cpSent = cpBegin + ich;
  179. else
  180. cpSent = cpNil;
  181. for (;;)
  182. {
  183. if (ich == 0)
  184. {
  185. if (cpBegin == cpMinCur)
  186. return cpMinCur; /* beginning of doc */
  187. cpBegin = (cpBegin > dcpChunk) ? cpBegin - dcpChunk : cp0;
  188. FetchRgch(&ich, rgch, docCur, cpBegin, cp, dcpChunk);
  189. }
  190. ch = rgch[--ich];
  191. CachePara( docCur, cpBegin + ich ); /* Needed for pictures */
  192. if (ch == chEol || ch == chSect || ch == chNewLine ||
  193. ch == chTab || vpapAbs.fGraphics )
  194. break; /* EOL Always ends a unit */
  195. if (sty == styWord)
  196. {
  197. if (wb != wbWhite)
  198. {
  199. if (WbFromCh(ch) != wb)
  200. break;
  201. }
  202. else
  203. wb = WbFromCh(ch);
  204. }
  205. else
  206. { /* Test for sentence. */
  207. switch (ch)
  208. {
  209. case chDot:
  210. case chBang:
  211. case chQMark:
  212. if (cpSent != cpNil)
  213. return cpSent;
  214. }
  215. switch (WbFromCh(ch))
  216. {
  217. case wbText:
  218. cpSent = cpBegin + ich;
  219. wb = wbText;
  220. break;
  221. case wbPunct:
  222. switch (wb)
  223. {
  224. case wbWhite:
  225. wb = wbPunct;
  226. break;
  227. case wbText:
  228. cpSent = cpBegin + ich;
  229. }
  230. break;
  231. case wbWhite:
  232. if (wb == wbPunct)
  233. cpSent = cpBegin + ich + 1;
  234. wb = wbWhite;
  235. break;
  236. }
  237. }
  238. }
  239. return cpBegin + ich + 1;
  240. }
  241. /* W B F R O M C H */
  242. int WbFromCh(ch)
  243. int ch;
  244. { /* Return word-breakness of ch */
  245. switch (ch)
  246. {
  247. case chSpace:
  248. case chEol:
  249. #ifdef CRLF
  250. case chReturn:
  251. #endif
  252. case chSect:
  253. case chTab:
  254. case chNewLine:
  255. case chNBSFile:
  256. return wbWhite;
  257. case chNRHFile:
  258. return wbText;
  259. default: /* we are using the ANSI char set that windows used */
  260. return ((isalpha(ch) || isdigit(ch))? wbText : wbPunct);
  261. }
  262. }
  263.