EDITOR.LST 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. Listing:
  2. 1 IMPLEMENTATION MODULE Editor;
  3. 2 (*
  4. 3 * REPERTOIRE
  5. 4 * Release 1.6
  6. 5 * By Charles Bradford and Cole Brecheen
  7. 6 * (c) Copyright 1985-1992 PMI
  8. 7 * Green Bay, Wisconsin
  9. 8 * All rights reserved
  10. 9 * (414) 468-6040
  11. 10 *
  12. 11 * $Header: D:/logfiles/mods/editor.mov 1.7 10 Mar 1991 15:26:46 coleb $
  13. 12 *
  14. 13 *)
  15. 14
  16. 15
  17. 16 (*$O-*)
  18. 17 (*We turn off optimization for the whole module to help avoid bugs in
  19. 18 Logitech's LONGINTs.*)
  20. 19
  21. 20
  22. 21 (*EntryDiag:
  23. 22 IMPORT Diagnostics;
  24. 23 :EntryDiag*)
  25. 24
  26. 25 IMPORT BigSets;
  27. 26 IMPORT ByteFiddler;
  28. 27 IMPORT GenLists;
  29. 28 IMPORT KbdInput;
  30. 29 IMPORT Key;
  31. 30 IMPORT ListUtils;
  32. 31 IMPORT LowLevel;
  33. 32 IMPORT M2Strings;
  34. 33 IMPORT MsColors;
  35. 34 IMPORT Numbers;
  36. 35 IMPORT NumTypes;
  37. 36 IMPORT PosUtils;
  38. 37 IMPORT ScrnTypes;
  39. 38 IMPORT ScrnUtl1;
  40. 39 IMPORT Spkr;
  41. 40 IMPORT StrConv;
  42. 41 IMPORT StrEdit;
  43. 42 IMPORT SYSTEM;
  44. 43 IMPORT UserOps;
  45. 44 IMPORT VEditor;
  46. 45 IMPORT VWindows;
  47. 46
  48. 47
  49. 48 VAR
  50. 49 Initialized : BOOLEAN;
  51. 50
  52. 51
  53. 52 CONST
  54. 53 LineLeng = 255;
  55. 54 DisplayLeng = 80;
  56. 55
  57. 56 TYPE
  58. 57 LineType = ARRAY [0..LineLeng] OF CHAR;
  59. ***** ^ not supported yet
  60. ***** ^ not supported yet
  61. 58 LongAndShort =
  62. 59 RECORD
  63. 60 CASE : BOOLEAN OF
  64. ***** ^ not supported yet
  65. ***** ^ 'POINTER' expected
  66. 61 TRUE: longi: LONGINT;
  67. 62 | FALSE: locard, hicard: CARDINAL;
  68. 63 END;
  69. 64 END;
  70. 65
  71. 66 VAR
  72. 67 DumType: CARDINAL;
  73. 68 blank : ARRAY [0..0] OF CHAR;
  74. 69 DeleteBuffer : GenLists.GenList;
  75. 70
  76. 71
  77. 72 PROCEDURE CountToStr( TheCount: LongAndShort;
  78. 73 VAR TheStr: ARRAY OF CHAR);
  79. 74 BEGIN
  80. 75 IF TheCount.hicard = 0 THEN
  81. 76 StrConv.CardinalToStr( TheCount.locard, 1, TheStr);
  82. 77 ELSE
  83. 78 StrConv.LongIntegerToStr( TheCount.longi, 1, TheStr);
  84. 79 END;
  85. 80 END CountToStr;
  86. 81
  87. 82
  88. 83 PROCEDURE DefaultEditor( VAR TheList: GenLists.GenList;
  89. 84 VAR Rec: VEditor.AnEdControlRec );
  90. 85
  91. 86 TYPE
  92. 87 WriteToScreenOrNot = (DoWrite, DontWrite);
  93. 88 VAR
  94. 89 BlankStr : ARRAY [0..DisplayLeng] OF CHAR;
  95. 90 Testing, DoExitBox : BOOLEAN;
  96. 91 (* Testing is true if want to see internals printed. *)
  97. 92 WindowHeight, ColsScrolled, MaxLength,
  98. 93 LastLineDeleted, TheRow, RLineCnt, TLine,
  99. 94 TheNdx : CARDINAL;
  100. 95 RCharCnt, TCharCnt : LongAndShort;
  101. 96 (* TheRow = the actual row on the screen where the cursor
  102. 97 is*)
  103. 98 (* Row1 = first row on screen that is in the editor*)
  104. 99 (* TheNdx = the column in the text, not on the screen,
  105. 100 where we are. Value starts at 0. TheNdx + Col1 is the
  106. 101 actual screen column*)
  107. 102 (* RCharCnt, RlineCnt = actual text size in characters and
  108. 103 lines*)
  109. 104 (* TCharCnt, Tline = cursor position in text (characters &
  110. 105 lines)*)
  111. 106 dumint: INTEGER;
  112. 107
  113. 108
  114. 109 PROCEDURE SetPromptColors( TheFrame: ScrnTypes.DisplayFrame );
  115. 110 BEGIN
  116. 111 VWindows.SetForeColor( TheFrame^.WindowHandle,
  117. 112 Rec.EdPromptFore );
  118. 113 VWindows.SetBackColor( TheFrame^.WindowHandle,
  119. 114 Rec.EdPromptBack );
  120. 115 VWindows.SetMonoAttr( TheFrame^.WindowHandle,
  121. 116 Rec.EdPromptAttrib );
  122. 117 END SetPromptColors;
  123. 118
  124. 119
  125. 120 PROCEDURE SetAttribOrColor( ForeColor, BackColor: MsColors.AColor;
  126. 121 attr: MsColors.AMonoAttribute );
  127. 122 BEGIN
  128. 123 VWindows.SetForeColor( Rec.WindowHandle, ForeColor );
  129. 124 VWindows.SetBackColor( Rec.WindowHandle, BackColor );
  130. 125 VWindows.SetMonoAttr( Rec.WindowHandle, attr );
  131. 126 END SetAttribOrColor;
  132. 127
  133. 128
  134. 129 PROCEDURE CheckMax(): BOOLEAN;
  135. 130 BEGIN
  136. 131 IF (Rec.MaxLines = 0) OR
  137. 132 (GenLists.ListLength( TheList ) < Rec.MaxLines) THEN
  138. 133 RETURN TRUE;
  139. 134 ELSE
  140. 135 Spkr.Noise( Spkr.Warble, Spkr.Normal, Spkr.Short);
  141. 136 RETURN FALSE;
  142. 137 END;
  143. 138 END CheckMax;
  144. 139
  145. 140 PROCEDURE UpdateFrameRec();
  146. 141 VAR
  147. 142 FieldRec: ScrnTypes.InputFieldRecord;
  148. 143 BEGIN
  149. 144 IF Rec.FrameRec # NIL THEN
  150. 145 IF GenLists.Initialized( Rec.FrameRec^.FieldList ) AND
  151. 146 (Rec.FrameRec^.CurrentField # 0) AND
  152. 147 (GenLists.ListLength( Rec.FrameRec^.FieldList ) > 0) THEN
  153. 148 IF (Rec.FrameRec^.CurrentField = 0) THEN
  154. 149 Rec.FrameRec^.CurrentField := 1;
  155. 150 END;
  156. 151 ScrnUtl1.GetFieldRec( Rec.FrameRec, Rec.FrameRec^.CurrentField,
  157. 152 FieldRec );
  158. 153 IF FieldRec.typ = ScrnTypes.EditorCode THEN
  159. 154 (*
  160. 155 ??
  161. 156 FieldRec.Col2 := Rec.Col2;
  162. 157 FieldRec.Row2 := Rec.Row2;
  163. 158 *)
  164. 159 FieldRec.TextRow1 := Rec.TextRow1;
  165. 160 FieldRec.CursorCol := Rec.CursorCol;
  166. 161 FieldRec.CursorRow := Rec.CursorRow;
  167. 162 FieldRec.MaxLines := Rec.MaxLines;
  168. 163 FieldRec.ChangeMade := Rec.ChangeMade;
  169. 164 FieldRec.ReadOnly := Rec.ReadOnly;
  170. 165 ScrnUtl1.PutFieldRec( FieldRec, Rec.FrameRec,
  171. 166 Rec.FrameRec^.CurrentField );
  172. 167 END;
  173. 168 END;
  174. 169 END;
  175. 170 END UpdateFrameRec;
  176. 171
  177. 172 PROCEDURE GetFrameRecData();
  178. 173 VAR
  179. 174 FieldRec: ScrnTypes.InputFieldRecord;
  180. 175 BEGIN
  181. 176 IF Rec.FrameRec # NIL THEN
  182. 177 Rec.WindowHandle := Rec.FrameRec^.WindowHandle;
  183. 178 IF GenLists.Initialized( Rec.FrameRec^.FieldList ) AND
  184. 179 (GenLists.ListLength( Rec.FrameRec^.FieldList ) > 0) THEN
  185. 180 IF (Rec.FrameRec^.CurrentField = 0) THEN
  186. 181 Rec.FrameRec^.CurrentField := 1;
  187. 182 END;
  188. 183 ScrnUtl1.GetFieldRec( Rec.FrameRec, Rec.FrameRec^.CurrentField,
  189. 184 FieldRec );
  190. 185 IF FieldRec.typ = ScrnTypes.EditorCode THEN
  191. 186 (*
  192. 187 ??
  193. 188 Rec.Col2 := FieldRec.Col2;
  194. 189 Rec.Row2 := FieldRec.Row2;
  195. 190 *)
  196. 191 Rec.TextRow1 := FieldRec.TextRow1;
  197. 192 Rec.CursorCol := FieldRec.CursorCol;
  198. 193 Rec.CursorRow := FieldRec.CursorRow;
  199. 194 Rec.MaxLines := FieldRec.MaxLines;
  200. 195 Rec.ChangeMade := FieldRec.ChangeMade;
  201. 196 Rec.ReadOnly := FieldRec.ReadOnly;
  202. 197 IF NOT ScrnUtl1.ListFromEdField( Rec.FrameRec,
  203. 198 Rec.FrameRec^.CurrentField, TheList ) THEN
  204. 199 (*Remember that a user might invoke a help sequence from
  205. 200 within the editor, which would require PushFrame/PopFrame
  206. 201 to save and restore the frame's lists. Since we're editing
  207. 202 one of them, we need to update our pointer, because the
  208. 203 saved copy will be in a different place.*)
  209. 204 END;
  210. 205 END;
  211. 206 END;
  212. 207 END;
  213. 208 END GetFrameRecData;
  214. 209
  215. 210 PROCEDURE findindent(str : ARRAY OF CHAR) : CARDINAL;
  216. 211 VAR
  217. 212 ind, leng : CARDINAL;
  218. 213 done : BOOLEAN;
  219. 214 BEGIN
  220. 215 done := FALSE;
  221. 216 ind := 0;
  222. 217 leng := M2Strings.Length(str);
  223. 218 IF leng#0 THEN
  224. 219 DEC(leng);
  225. 220 REPEAT
  226. 221 IF (str[ind]#blank[0]) THEN
  227. 222 done := TRUE;
  228. 223 ELSIF (ind>=leng) THEN
  229. 224 done := TRUE;
  230. 225 ind := HIGH(str) + 1;
  231. 226 ELSE
  232. 227 INC(ind);
  233. 228 END;
  234. 229 UNTIL done;
  235. 230 ELSE
  236. 231 ind := HIGH(str) + 1;
  237. 232 END;
  238. 233 RETURN (ind);
  239. 234 END findindent;
  240. 235
  241. 236 PROCEDURE WriteStrings(TextLine, baserow, endrow : CARDINAL);
  242. 237 VAR
  243. 238 clrstr: ARRAY [0..DisplayLeng] OF CHAR;
  244. 239 clrlngth, tmpsize, leng, tmprow : CARDINAL;
  245. 240 tmpadr: SYSTEM.ADDRESS;
  246. 241 BEGIN
  247. 242 LowLevel.Fill( SYSTEM.ADR(clrstr), DisplayLeng + 1, blank);
  248. 243 leng := GenLists.ListLength( TheList);
  249. 244 M2Strings.Assign(BlankStr, clrstr);
  250. 245 tmprow := baserow - 1;
  251. 246 WHILE (TextLine <= leng) AND (tmprow < endrow) DO
  252. 247 INC( tmprow);
  253. 248 GenLists.GetElmtAdr( TheList, TextLine, tmpadr, tmpsize, DumType);
  254. 249 tmpsize := LowLevel.ScanEQ( tmpsize, 0C, tmpadr );
  255. 250 IF tmpsize < ColsScrolled THEN
  256. 251 clrlngth := MaxLength;
  257. 252 tmpsize := 0;
  258. 253 (*set tmpsize to 0 because none of the string will
  259. 254 show.*)
  260. 255 ELSE
  261. 256 IF (tmpsize - ColsScrolled) > MaxLength THEN
  262. 257 tmpsize := MaxLength;
  263. 258 clrlngth := 0;
  264. 259 ELSE
  265. 260 tmpsize := Numbers.Min( tmpsize - ColsScrolled, MaxLength );
  266. 261 clrlngth := MaxLength - tmpsize;
  267. 262 END;
  268. 263 IF tmpsize > 0 THEN
  269. 264 VWindows.DrawStr( Rec.WindowHandle, Rec.Col1,
  270. 265 tmprow, LowLevel.AddAddr(tmpadr, ColsScrolled),
  271. 266 tmpsize );
  272. 267 END;
  273. 268 END;
  274. 269 IF clrlngth > 0 THEN
  275. 270 VWindows.DrawStr( Rec.WindowHandle,
  276. 271 Rec.Col1 + tmpsize, tmprow, SYSTEM.ADR(clrstr),
  277. 272 clrlngth );
  278. 273 END;
  279. 274 INC( TextLine);
  280. 275 END;
  281. 276 IF (tmprow < endrow) AND (endrow = Rec.Row2) THEN
  282. 277 VWindows.ClearPart( Rec.WindowHandle,
  283. 278 Rec.Col1, tmprow + 1, Rec.Col2, Rec.Row2);
  284. 279 END;
  285. 280 END WriteStrings;
  286. 281
  287. 282 PROCEDURE OvrOrIns( VAR TheStr: ARRAY OF CHAR);
  288. 283 BEGIN
  289. 284 IF Rec.overwriting THEN
  290. 285 StrEdit.AssignStr( 'Overwrite', TheStr);
  291. 286 ELSE
  292. 287 StrEdit.AssignStr( ' Insert ', TheStr);
  293. 288 END;
  294. 289 END OvrOrIns;
  295. 290
  296. 291 PROCEDURE WriteFooter();
  297. 292 VAR
  298. 293 dumstr : ARRAY [0..DisplayLeng] OF CHAR;
  299. 294 tmpstr : ARRAY [0..10] OF CHAR;
  300. 295 SavedFore, SavedBack : MsColors.AColor;
  301. 296 SavedAttr : MsColors.AMonoAttribute;
  302. 297 BEGIN
  303. 298 IF Rec.FrameRec # NIL THEN
  304. 299 SavedFore := VWindows.ForeColor( Rec.WindowHandle );
  305. 300 SavedBack := VWindows.BackColor( Rec.WindowHandle );
  306. 301 SavedAttr := VWindows.MonoAttr( Rec.WindowHandle );
  307. 302 SetPromptColors( Rec.FrameRec );
  308. 303 END;
  309. 304 CountToStr(RCharCnt, tmpstr);
  310. 305 M2Strings.Concat('TEXT SIZE: chars:', tmpstr, dumstr);
  311. 306 StrEdit.LeftJustify( dumstr, 23 );
  312. 307 StrEdit.Append(dumstr, ' lines:');
  313. 308 StrConv.CardinalToStr(RLineCnt, 1, tmpstr);
  314. 309 StrEdit.Append(dumstr, tmpstr);
  315. 310 StrEdit.LeftJustify( dumstr, 33 );
  316. 311 StrEdit.Append(dumstr, ' POSITION: char:');
  317. 312 CountToStr( TCharCnt, tmpstr);
  318. 313 StrEdit.Append(dumstr, tmpstr);
  319. 314 StrEdit.LeftJustify( dumstr, 54 );
  320. 315 StrEdit.Append(dumstr, ' line:');
  321. 316 StrConv.CardinalToStr(TLine, 1, tmpstr);
  322. 317 StrEdit.Append(dumstr, tmpstr);
  323. 318 StrEdit.LeftJustify( dumstr, 65 );
  324. 319 StrEdit.Append(dumstr, 'MODE:');
  325. 320 OvrOrIns( tmpstr);
  326. 321 StrEdit.Append(dumstr, tmpstr);
  327. 322 VWindows.DrawStr( Rec.WindowHandle,2, Rec.CountRow,
  328. 323 SYSTEM.ADR(dumstr), M2Strings.Length(dumstr) );
  329. 324 IF Rec.FrameRec # NIL THEN
  330. 325 VWindows.SetForeColor( Rec.WindowHandle, SavedFore );
  331. 326 VWindows.SetBackColor( Rec.WindowHandle, SavedBack );
  332. 327 VWindows.SetMonoAttr( Rec.WindowHandle, SavedAttr );
  333. 328 END;
  334. 329 END WriteFooter;
  335. 330
  336. 331 PROCEDURE AddCLCount( CharTotalDiff: LONGINT; LineTotalDiff: INTEGER;
  337. 332 CharPosDiff: LONGINT; LinePosDiff : INTEGER );
  338. 333 VAR
  339. 334 tmpstr : ARRAY [0..20] OF CHAR;
  340. 335 TmpLong : LONGINT;
  341. 336 SavedFore, SavedBack : MsColors.AColor;
  342. 337 SavedAttr : MsColors.AMonoAttribute;
  343. 338 BEGIN
  344. 339 TLine := INTEGER( INTEGER(TLine) + LinePosDiff );
  345. 340 IF Rec.DoCounting THEN
  346. 341 IF Rec.FrameRec # NIL THEN
  347. 342 SavedFore := VWindows.ForeColor( Rec.WindowHandle );
  348. 343 SavedBack := VWindows.BackColor( Rec.WindowHandle );
  349. 344 SavedAttr := VWindows.MonoAttr( Rec.WindowHandle );
  350. 345 SetPromptColors( Rec.FrameRec );
  351. 346 END;
  352. 347 IF LineTotalDiff # 0 THEN
  353. 348 RLineCnt := INTEGER(INTEGER(RLineCnt) + LineTotalDiff);
  354. 349 StrConv.CardinalToStr(RLineCnt, 1, tmpstr);
  355. 350 StrEdit.Append(tmpstr, ' ');
  356. 351 StrEdit.SetLength(tmpstr, 4);
  357. 352 VWindows.DrawStr( Rec.WindowHandle, 31,
  358. 353 Rec.CountRow, SYSTEM.ADR(tmpstr), 4);
  359. 354 END;
  360. 355 IF LinePosDiff#0 THEN
  361. 356 StrConv.CardinalToStr(TLine, 1, tmpstr);
  362. 357 StrEdit.Append(tmpstr, ' ');
  363. 358 StrEdit.SetLength(tmpstr, 4);
  364. 359 VWindows.DrawStr( Rec.WindowHandle,62, Rec.CountRow,
  365. 360 SYSTEM.ADR(tmpstr), 4);
  366. 361 END;
  367. 362 IF CharTotalDiff # NumTypes.L0 THEN
  368. 363 TmpLong := CharTotalDiff;
  369. 364 RCharCnt.longi := RCharCnt.longi + TmpLong;
  370. 365 CountToStr( RCharCnt, tmpstr);
  371. 366 StrEdit.Append(tmpstr, ' ');
  372. 367 StrEdit.SetLength(tmpstr, 5);
  373. 368 VWindows.DrawStr( Rec.WindowHandle,19, Rec.CountRow,
  374. 369 SYSTEM.ADR(tmpstr), 5);
  375. 370 END;
  376. 371 IF CharPosDiff # NumTypes.L0 THEN
  377. 372 TmpLong := CharPosDiff;
  378. 373 TCharCnt.longi := TCharCnt.longi + TmpLong;
  379. 374 CountToStr( TCharCnt, tmpstr);
  380. 375 StrEdit.Append(tmpstr, ' ');
  381. 376 StrEdit.SetLength(tmpstr, 5);
  382. 377 VWindows.DrawStr( Rec.WindowHandle,51, Rec.CountRow,
  383. 378 SYSTEM.ADR(tmpstr), 5);
  384. 379 END;
  385. 380 IF Rec.FrameRec # NIL THEN
  386. 381 VWindows.SetForeColor( Rec.WindowHandle, SavedFore );
  387. 382 VWindows.SetBackColor( Rec.WindowHandle, SavedBack );
  388. 383 VWindows.SetMonoAttr( Rec.WindowHandle, SavedAttr );
  389. 384 END;
  390. 385 END;
  391. 386 VWindows.GotoXY( Rec.WindowHandle, Rec.Col1 +
  392. 387 TheNdx - ColsScrolled, TheRow);
  393. 388 END AddCLCount;
  394. 389
  395. 390 PROCEDURE CountChars(Rtmptr : CARDINAL; VAR Rchars : LONGINT;
  396. 391 VAR Rlines : CARDINAL; Ttmptr : CARDINAL;
  397. 392 VAR Tchars : LONGINT);
  398. 393 VAR
  399. 394 leng : CARDINAL;
  400. 395 BEGIN
  401. 396 IF NOT Rec.DoCounting THEN
  402. 397 Rchars := NumTypes.L1;
  403. 398 Rlines := 1;
  404. 399 Tchars := NumTypes.L1;
  405. 400 (*Added 25 May 87 to prevent uninitialized values*)
  406. 401 RETURN;
  407. 402 END;
  408. 403 leng := GenLists.ListLength( TheList);
  409. 404 (*count all chars starting WITH Rtmptr*)
  410. 405 Rlines := 0;
  411. 406 Rchars := NumTypes.L1;
  412. 407 (*put 1+ chars and lines before Ttmptr in Tchars and Tlines*)
  413. 408 Tchars := NumTypes.L1;
  414. 409 WHILE Rtmptr <= leng DO
  415. 410 Rlines := Rlines + 1;
  416. 411 IF Rtmptr=Ttmptr THEN
  417. 412 Tchars := Rchars;
  418. 413 END;
  419. 414 Rchars := Rchars + Numbers.Lc( ListUtils.ElmtSize(TheList,Rtmptr) + 2 );
  420. 415 INC( Rtmptr);
  421. 416 END;
  422. 417 END CountChars;
  423. 418
  424. 419
  425. 420 PROCEDURE TheLength(): CARDINAL;
  426. 421 (* Returns length of current line *)
  427. 422 BEGIN
  428. 423 RETURN ListUtils.ElmtSize( TheList, TLine);
  429. 424 END TheLength;
  430. 425
  431. 426
  432. 427 PROCEDURE MoveAcrossTo(NewNdx : INTEGER);
  433. 428 VAR
  434. 429 charsmoved : INTEGER;
  435. 430 redraw : BOOLEAN;
  436. 431 lngth : CARDINAL;
  437. 432 BEGIN
  438. 433 lngth := TheLength();
  439. 434 IF (CARDINAL(NewNdx) >= lngth) AND (TheNdx >= lngth) THEN
  440. 435 charsmoved := 0;
  441. 436 ELSE
  442. 437 IF (CARDINAL(NewNdx) >= lngth) AND
  443. 438 (TheNdx < lngth) THEN
  444. 439 (*We've crossed over to the right of the trailing CR/LF.*)
  445. 440 charsmoved := (lngth - TheNdx) + 2;
  446. 441 ELSIF (CARDINAL(NewNdx) < lngth) AND
  447. 442 (TheNdx >= lngth) THEN
  448. 443 (*We've crossed over to the left of the trailing CR/LF.*)
  449. 444 charsmoved := (NewNdx - INTEGER(lngth)) - 2;
  450. 445 ELSE
  451. 446 charsmoved := NewNdx - INTEGER(TheNdx);
  452. 447 IF (charsmoved = 0) THEN
  453. 448 RETURN;
  454. 449 END;
  455. 450 END;
  456. 451 END;
  457. 452 TheNdx := NewNdx;
  458. 453 IF (TheNdx < ColsScrolled) THEN
  459. 454 ColsScrolled := TheNdx;
  460. 455 redraw := TRUE;
  461. 456 ELSIF (TheNdx > (ColsScrolled + MaxLength - 1)) THEN
  462. 457 ColsScrolled := TheNdx - MaxLength + 1;
  463. 458 redraw := TRUE;
  464. 459 ELSE
  465. 460 redraw := FALSE;
  466. 461 END;
  467. 462 AddCLCount( NumTypes.L0, 0, Numbers.Li(charsmoved), 0);
  468. 463 IF redraw THEN
  469. 464 WriteStrings( TLine -
  470. 465 (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  471. 466 END;
  472. 467 END MoveAcrossTo;
  473. 468
  474. 469
  475. 470 PROCEDURE MoveVerticallyTo( NewTLine: CARDINAL );
  476. 471 VAR
  477. 472 TmpSize, ColNow, RowNow, LstLngth, TmpLineCount : CARDINAL;
  478. 473 TmpL, BytesSkipped : LONGINT;
  479. 474 redrawing, MovingUp : BOOLEAN;
  480. 475 addrow, addchar, dist : INTEGER;
  481. 476 BEGIN
  482. 477 LstLngth := GenLists.ListLength( TheList );
  483. 478 addrow := 0;
  484. 479 addchar := 0;
  485. 480 IF NewTLine > LstLngth THEN
  486. 481 (*We'll add a line if the line we're on is the last line
  487. 482 and it isn't blank.*)
  488. 483 IF (TLine = LstLngth) AND
  489. 484 (ListUtils.ElmtSize(TheList, TLine) > 0) THEN
  490. 485 IF CheckMax() THEN
  491. 486 GenLists.ListInsert( '', DumType, TheList, TLine + 1);
  492. 487 addrow := 1;
  493. 488 addchar := 2;
  494. 489 INC( LstLngth );
  495. 490 END;
  496. 491 END;
  497. 492 (*otherwise we don't let them move past last line*)
  498. 493 NewTLine := LstLngth;
  499. 494 ELSIF NewTLine < 1 THEN
  500. 495 NewTLine := 1;
  501. 496 END;
  502. 497 IF TLine > NewTLine THEN
  503. 498 MovingUp := TRUE;
  504. 499 ELSIF TLine < NewTLine THEN
  505. 500 MovingUp := FALSE;
  506. 501 ELSE
  507. 502 RETURN;
  508. 503 END;
  509. 504
  510. 505 (*Now we count the bytes we will be skipping.*)
  511. 506 TmpLineCount := TLine;
  512. 507 BytesSkipped := NumTypes.L0;
  513. 508 IF MovingUp THEN
  514. 509 WHILE (TmpLineCount >= NewTLine) DO
  515. 510 IF TmpLineCount > LstLngth THEN
  516. 511 (*This can happen if we've just deleted the last line
  517. 512 and we're moving up to what is now the new last line.*)
  518. 513 TmpL := NumTypes.L0;
  519. 514 ELSE
  520. 515 TmpL := Numbers.Lc( ListUtils.ElmtSize( TheList,
  521. 516 TmpLineCount ));
  522. 517 (*Workaround for a Logitech LONGINT bug.*)
  523. 518 END;
  524. 519 BytesSkipped := BytesSkipped + TmpL + NumTypes.L2;
  525. 520 DEC( TmpLineCount );
  526. 521 END;
  527. 522 (*Adjust BytesSkipped because we may not have actually skipped
  528. 523 over some of the bytes on the line we were on. It depends
  529. 524 on whether the cursor was beyond the end of the line at the
  530. 525 time.*)
  531. 526 IF TLine > LstLngth THEN
  532. 527 TmpSize := 0;
  533. 528 ELSE
  534. 529 TmpSize := ListUtils.ElmtSize( TheList, TLine );
  535. 530 END;
  536. 531 IF TheNdx < TmpSize THEN
  537. 532 TmpSize := TmpSize - TheNdx + 2;
  538. 533 (*Otherwise the cursor was beyond the end of the line, so
  539. 534 we did skip over the full length of the line plus the
  540. 535 CR/LF at the end of it. We don't have to subtract
  541. 536 anything*)
  542. 537 BytesSkipped := BytesSkipped - Numbers.Lc(TmpSize);
  543. 538 END;
  544. 539 TmpSize := ListUtils.ElmtSize( TheList, NewTLine );
  545. 540 (*Now determine whether we have skipped over all
  546. 541 of the line we're moving to. If we don't adjust
  547. 542 BytesSkipped, it tells AddCLCount that we have
  548. 543 skipped over the whole thing.*)
  549. 544 IF TheNdx < TmpSize THEN
  550. 545 BytesSkipped := BytesSkipped - Numbers.Lc(TheNdx);
  551. 546 ELSE
  552. 547 TmpSize := TmpSize + 2;
  553. 548 BytesSkipped := BytesSkipped - Numbers.Lc(TmpSize);
  554. 549 END;
  555. 550 BytesSkipped := -BytesSkipped;
  556. 551 ELSE
  557. 552 WHILE (TmpLineCount <= NewTLine) DO
  558. 553 TmpL := Numbers.Lc( ListUtils.ElmtSize( TheList, TmpLineCount ));
  559. 554 (*Workaround for a Logitech LONGINT bug.*)
  560. 555 BytesSkipped := BytesSkipped + TmpL + NumTypes.L2;
  561. 556 INC( TmpLineCount );
  562. 557 END;
  563. 558 (*Now we subtract the part of the line we're on that we didn't
  564. 559 actually skip.*)
  565. 560 IF TLine <= LstLngth THEN
  566. 561 TmpL := Numbers.Lc( Numbers.Min(TheNdx, TheLength() ) );
  567. 562 IF Numbers.C(TmpL) >= ListUtils.ElmtSize(TheList, TLine) THEN
  568. 563 TmpL := TmpL + NumTypes.L2;
  569. 564 END;
  570. 565 BytesSkipped := BytesSkipped - TmpL;
  571. 566 END;
  572. 567 (*And now we subtract the part of the new line that we haven't
  573. 568 yet skipped.*)
  574. 569 TmpSize := ListUtils.ElmtSize(TheList, NewTLine);
  575. 570 IF TheNdx < TmpSize THEN
  576. 571 TmpSize := TmpSize - TheNdx + 2;
  577. 572 BytesSkipped := BytesSkipped - Numbers.Lc(TmpSize);
  578. 573 END;
  579. 574 END;
  580. 575
  581. 576 dist := INTEGER(NewTLine) - INTEGER(TLine);
  582. 577
  583. 578 (*Now determine whether we can get by with just moving the cursor
  584. 579 instead of redrawing some or all of the window.*)
  585. 580 IF MovingUp THEN
  586. 581 redrawing := (INTEGER(TheRow) + dist) < INTEGER(Rec.Row1);
  587. 582 ELSE
  588. 583 redrawing := (INTEGER(TheRow) + dist) > INTEGER(Rec.Row2);
  589. 584 END;
  590. 585 IF NOT redrawing THEN
  591. 586 TheRow := INTEGER(INTEGER(TheRow) + dist);
  592. 587 VWindows.GetCursorCoords( Rec.WindowHandle,
  593. 588 ColNow, RowNow );
  594. 589 VWindows.GotoXY( Rec.WindowHandle, ColNow,
  595. 590 CARDINAL(INTEGER(RowNow) + dist) );
  596. 591 AddCLCount( Numbers.Li(addchar), addrow, BytesSkipped, dist );
  597. 592 RETURN;
  598. 593 END;
  599. 594
  600. 595 (*We know we have to redraw at least some of the window. The
  601. 596 next easy case is redrawing the whole thing.*)
  602. 597 IF ABS(dist) >= INTEGER(WindowHeight) THEN
  603. 598 IF (NewTLine > (TheRow - Rec.Row1)) AND
  604. 599 (NOT (NewTLine = LstLngth)) THEN
  605. 600 WriteStrings( NewTLine - (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  606. 601 ELSE
  607. 602 (*We're moving more than a page's length, so we'll position the
  608. 603 cursor to the top of the window unless we're going to the
  609. 604 very end--in that case we position it to the bottom.*)
  610. 605 VWindows.GetCursorCoords( Rec.WindowHandle,
  611. 606 ColNow, RowNow );
  612. 607 IF (NewTLine = LstLngth) AND (NewTLine >= WindowHeight) THEN
  613. 608 WriteStrings( NewTLine - WindowHeight + 1, Rec.Row1, Rec.Row2 );
  614. 609 TheRow := Rec.Row2;
  615. 610 VWindows.GotoXY( Rec.WindowHandle, ColNow,
  616. 611 Rec.Row2 );
  617. 612 ELSE
  618. 613 WriteStrings( NewTLine, Rec.Row1, Rec.Row2 );
  619. 614 TheRow := Rec.Row1;
  620. 615 VWindows.GotoXY( Rec.WindowHandle, ColNow,
  621. 616 Rec.Row1 );
  622. 617 END;
  623. 618 END;
  624. 619 AddCLCount( Numbers.Li(addchar), addrow, BytesSkipped, dist );
  625. 620 RETURN;
  626. 621 END;
  627. 622
  628. 623 (*Looks like we'll have to scroll part of the window and redraw
  629. 624 the rest of it.*)
  630. 625 IF NOT VWindows.ScrollVertically( Rec.WindowHandle,
  631. 626 Rec.Col1, Rec.Row1, Rec.Col2, Rec.Row2, dist ) THEN
  632. 627 (*The window manager they've chosen doesn't support a
  633. 628 fast vertical scroll, so we can redraw the whole thing
  634. 629 and leave.*)
  635. 630 WriteStrings( NewTLine - (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  636. 631 AddCLCount( Numbers.Li(addchar), addrow, BytesSkipped, dist );
  637. 632 RETURN;
  638. 633 END;
  639. 634
  640. 635 IF MovingUp THEN
  641. 636 (*We have to redraw the top of the window.*)
  642. 637 WriteStrings( NewTLine - (TheRow - Rec.Row1), Rec.Row1,
  643. 638 Rec.Row1 + CARDINAL(ABS(dist)) - 1 );
  644. 639 ELSE
  645. 640 (*We have to redraw the bottom of the window.*)
  646. 641 WriteStrings( NewTLine - CARDINAL(ABS(dist)) + 1,
  647. 642 Rec.Row2 - CARDINAL(ABS(dist)) + 1, Rec.Row2 );
  648. 643 END;
  649. 644 AddCLCount( Numbers.Li(addchar), addrow, BytesSkipped, dist );
  650. 645 END MoveVerticallyTo;
  651. 646
  652. 647
  653. 648 PROCEDURE PageUp();
  654. 649 BEGIN
  655. 650 IF (TheRow > Rec.Row1) OR (TLine = 1) THEN
  656. 651 MoveVerticallyTo( TLine - (TheRow - Rec.Row1) );
  657. 652 ELSIF WindowHeight >= TLine THEN
  658. 653 MoveVerticallyTo( 1 );
  659. 654 ELSE
  660. 655 MoveVerticallyTo( TLine - WindowHeight );
  661. 656 END;
  662. 657 END PageUp;
  663. 658
  664. 659 PROCEDURE PageDown();
  665. 660 BEGIN
  666. 661 IF (TheRow < Rec.Row2) OR (TLine = GenLists.ListLength(TheList)) THEN
  667. 662 MoveVerticallyTo( TLine + (Rec.Row2 - TheRow) );
  668. 663 ELSE
  669. 664 MoveVerticallyTo( TLine + WindowHeight );
  670. 665 END;
  671. 666 END PageDown;
  672. 667
  673. 668
  674. 669 PROCEDURE DeleteAChar( spacesback : CARDINAL);
  675. 670 VAR
  676. 671 tmpadr: SYSTEM.ADDRESS;
  677. 672 null: CHAR;
  678. 673 tmpsize, NewNdx: CARDINAL;
  679. 674 BEGIN
  680. 675 null := 0C;
  681. 676 IF TheNdx > TheLength() THEN
  682. 677 MoveAcrossTo( TheLength() );
  683. 678 END;
  684. 679 NewNdx := TheNdx - spacesback;
  685. 680 MoveAcrossTo( NewNdx );
  686. 681 (*This changes the value of TheNdx. We have to do it
  687. 682 before the ShiftArrayLeft because MoveAcrossTo won't
  688. 683 update our character position if it thinks we're
  689. 684 moving around in the void beyond the end of the line.*)
  690. 685 GenLists.GetElmtAdr( TheList, TLine, tmpadr, tmpsize, DumType);
  691. 686 LowLevel.ShiftArrayLeft( LowLevel.AddAddr(tmpadr, NewNdx),
  692. 687 tmpsize - NewNdx, 1 );
  693. 688 (*Now we have to make sure we've truncated the line, because
  694. 689 the ShiftArrayLeft will only do so if it moves a trailing
  695. 690 null with the rest of the string.*)
  696. 691 IF tmpsize > 0 THEN
  697. 692 ListUtils.OverwriteElmt( TheList, TLine, SYSTEM.ADR(null), 1,
  698. 693 tmpsize - 1 );
  699. 694 END;
  700. 695 WriteStrings( TLine, TheRow, TheRow );
  701. 696 IF NewNdx >= TheLength() THEN
  702. 697 (*We have to increment the character position by 2 if we
  703. 698 wound up beyond the line length--the MoveAcrossTo didn't
  704. 699 know what the ending line length would be.*)
  705. 700 AddCLCount( Numbers.Li(-1), 0, NumTypes.L2, 0);
  706. 701 ELSE
  707. 702 AddCLCount( Numbers.Li(-1), 0, NumTypes.L0, 0);
  708. 703 END;
  709. 704 END DeleteAChar;
  710. 705
  711. 706
  712. 707 PROCEDURE NewLink(VAR oldptr : CARDINAL; curind : CARDINAL);
  713. 708 VAR
  714. 709 newline : LineType;
  715. 710 BEGIN
  716. 711 (*We don't have to check MaxLines here because NewLink is
  717. 712 only called in BumpWord, which we don't call if we're
  718. 713 close to the limit.*)
  719. 714 LowLevel.Fill( SYSTEM.ADR( newline), curind, blank);
  720. 715 StrEdit.SetLength( newline, curind);
  721. 716 GenLists.ListInsert( newline, GenLists.StrCode, TheList, oldptr + 1);
  722. 717 END NewLink;
  723. 718
  724. 719
  725. 720 PROCEDURE ReplaceWith(TheChr : CHAR);
  726. 721 VAR
  727. 722 LinesAdded, CharsAdded : INTEGER;
  728. 723 StartLine, CursorLine, CursorCol: CARDINAL;
  729. 724 RoomOnThisLine, BeyondEnd : BOOLEAN;
  730. 725 BEGIN
  731. 726 (* First we'll put the character into the list. Then we'll worry
  732. 727 about whether we have to wrap or scroll to display it. *)
  733. 728 CharsAdded := 0;
  734. 729 BeyondEnd := (TheNdx >= ListUtils.ElmtSize(TheList, TLine));
  735. 730 IF BeyondEnd THEN
  736. 731 WHILE (TheNdx > ListUtils.ElmtSize(TheList, TLine)) DO
  737. 732 ListUtils.InsertIntoElmt( TheList, TLine,
  738. 733 SYSTEM.ADR(blank), 1, 65535 );
  739. 734 (*pad with blanks out to TheNdx, if necessary*)
  740. 735 INC(CharsAdded);
  741. 736 END;
  742. 737 TCharCnt.longi := TCharCnt.longi - NumTypes.L2;
  743. 738 (*We do this to compensate for the fact that MoveAcrossTo
  744. 739 will think we've crossed over a CR/LF.*)
  745. 740 ListUtils.InsertIntoElmt( TheList, TLine,
  746. 741 SYSTEM.ADR(TheChr), 1, 65535 );
  747. 742 (*append TheChr to the string at position TLine*)
  748. 743 INC(CharsAdded);
  749. 744 ELSE
  750. 745 IF Rec.overwriting THEN
  751. 746 ListUtils.OverwriteElmt( TheList, TLine,
  752. 747 SYSTEM.ADR(TheChr), 1, TheNdx );
  753. 748 CharsAdded := 0;
  754. 749 ELSE
  755. 750 ListUtils.InsertIntoElmt( TheList, TLine,
  756. 751 SYSTEM.ADR(TheChr), 1, TheNdx );
  757. 752 CharsAdded := 1;
  758. 753 END;
  759. 754 END;
  760. 755
  761. 756 RoomOnThisLine := (NOT Rec.Wrapping) OR
  762. 757 (ListUtils.ElmtSize(TheList, TLine) < MaxLength);
  763. 758 IF RoomOnThisLine THEN
  764. 759 MoveAcrossTo( TheNdx + 1 );
  765. 760 WriteStrings( TLine, TheRow, TheRow );
  766. 761 AddCLCount(Numbers.Li(CharsAdded), 0, NumTypes.L0, 0);
  767. 762 ELSE
  768. 763 StartLine := TLine;
  769. 764 CursorLine := TLine;
  770. 765 CursorCol := TheNdx;
  771. 766 ListUtils.ReformPara( TheList,
  772. 767 ListUtils.IndentationAt(TheList, TLine), MaxLength, StartLine,
  773. 768 CursorLine, CursorCol, LinesAdded, CharsAdded, TCharCnt.longi );
  774. 769 AddCLCount( Numbers.Li(CharsAdded), LinesAdded, NumTypes.L0, 0 );
  775. 770 MoveAcrossTo( 0 );
  776. 771 (*Makes sure part of the current word isn't scrolled out of the
  777. 772 window. *)
  778. 773 MoveAcrossTo( CursorCol + 1 );
  779. 774 MoveVerticallyTo( CursorLine );
  780. 775 WriteStrings( TLine - (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  781. 776 END;
  782. 777 END ReplaceWith;
  783. 778
  784. 779
  785. 780 PROCEDURE ScrollRegion( row1, row2 : CARDINAL; dist: INTEGER );
  786. 781 VAR
  787. 782 NewTopLine: INTEGER;
  788. 783 BEGIN
  789. 784 NewTopLine := INTEGER(TLine - (TheRow - Rec.Row1)) +
  790. 785 INTEGER(row1 - Rec.Row1) + dist;
  791. 786 IF NOT VWindows.ScrollVertically( Rec.WindowHandle,
  792. 787 Rec.Col1, row1, Rec.Col2, row2, dist ) THEN
  793. 788 NewTopLine := Numbers.Min( NewTopLine, 1 );
  794. 789 WriteStrings( NewTopLine, row1, row2 );
  795. 790 RETURN;
  796. 791 END;
  797. 792 IF NewTopLine < 1 THEN
  798. 793 (*They want to move down by more lines than we have to fill with.*)
  799. 794 NewTopLine := 1 + ABS(dist);
  800. 795 INC( row1, CARDINAL(ABS(dist)) );
  801. 796 END;
  802. 797 IF dist > 0 THEN
  803. 798 WriteStrings( CARDINAL(NewTopLine) + (row2 - row1) -
  804. 799 CARDINAL(dist), Rec.Row2 - CARDINAL(dist) + 1,
  805. 800 Rec.Row2 );
  806. 801 ELSE
  807. 802 WriteStrings( CARDINAL(NewTopLine) + CARDINAL(ABS(dist)),
  808. 803 row1, CARDINAL(INTEGER(row1) + ABS(dist) - 1) );
  809. 804 END;
  810. 805 END ScrollRegion;
  811. 806
  812. 807
  813. 808 PROCEDURE Reformat();
  814. 809 VAR
  815. 810 LinesAdded, CharsAdded: INTEGER;
  816. 811 StartLine, CursorLine, CursorCol: CARDINAL;
  817. 812 BEGIN
  818. 813 StartLine := TLine;
  819. 814 CursorLine := TLine;
  820. 815 CursorCol := TheNdx;
  821. 816 ListUtils.ReformPara( TheList,
  822. 817 ListUtils.IndentationAt(TheList, StartLine), MaxLength, StartLine,
  823. 818 CursorLine, CursorCol, LinesAdded, CharsAdded, TCharCnt.longi );
  824. 819 AddCLCount( Numbers.Li(CharsAdded), LinesAdded, NumTypes.L0, 0 );
  825. 820 MoveAcrossTo( CursorCol );
  826. 821 MoveVerticallyTo( CursorLine );
  827. 822 WriteStrings( TLine - (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  828. 823 END Reformat;
  829. 824
  830. 825
  831. 826 PROCEDURE InsertDeleteBuffer();
  832. 827 VAR
  833. 828 BufLngth: CARDINAL;
  834. 829 CharsAdded, tmpl: LONGINT;
  835. 830 BEGIN
  836. 831 BufLngth := GenLists.ListLength( DeleteBuffer );
  837. 832 IF BufLngth = 0 THEN
  838. 833 RETURN;
  839. 834 END;
  840. 835 ListUtils.InsertElmtsOf( DeleteBuffer, 1, BufLngth,
  841. 836 TheList, TLine );
  842. 837 tmpl := ListUtils.CharCount( DeleteBuffer, 1, 65535 );
  843. 838 IF tmpl > NumTypes.L65535 THEN
  844. 839 (*If they try to copy more than 64K at once, we throw
  845. 840 up our hands; the text gets inserted correctly, but
  846. 841 we don't bother to position the cursor after it. We
  847. 842 just go to the top and let them figure out where they
  848. 843 were.*)
  849. 844 RCharCnt.longi := RCharCnt.longi + tmpl;
  850. 845 RLineCnt := RLineCnt + BufLngth;
  851. 846 MoveVerticallyTo( 1 );
  852. 847 MoveAcrossTo( 0 );
  853. 848 CharsAdded := tmpl;
  854. 849 AddCLCount( CharsAdded, BufLngth,
  855. 850 NumTypes.L0, 0 );
  856. 851 END;
  857. 852 CharsAdded := tmpl;
  858. 853 AddCLCount( CharsAdded, BufLngth,
  859. 854 NumTypes.L0, 0 );
  860. 855 WriteStrings( TLine -
  861. 856 (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  862. 857 MoveVerticallyTo( TLine + BufLngth );
  863. 858 END InsertDeleteBuffer;
  864. 859
  865. 860 PROCEDURE DeleteALine();
  866. 861 VAR
  867. 862 delsize : INTEGER;
  868. 863 BEGIN
  869. 864 delsize := 2 + ListUtils.ElmtSize( TheList, TLine );
  870. 865 IF TLine # LastLineDeleted THEN
  871. 866 IF GenLists.Initialized( DeleteBuffer ) THEN
  872. 867 GenLists.DisposeList( DeleteBuffer );
  873. 868 END;
  874. 869 GenLists.NewList( DeleteBuffer );
  875. 870 LastLineDeleted := TLine;
  876. 871 END;
  877. 872 ListUtils.InsertElmtsOf( TheList, TLine, 1, DeleteBuffer, 65535 );
  878. 873 GenLists.ListDelete( TheList, TLine, 1);
  879. 874 IF TLine <= GenLists.ListLength( TheList) THEN
  880. 875 (*this isn't the last line*)
  881. 876 WriteStrings( TLine, TheRow, Rec.Row2 );
  882. 877 AddCLCount( Numbers.Li(-delsize), -1, NumTypes.L0, 0);
  883. 878 ELSIF TLine # 1 THEN
  884. 879 (*this is the last line of many*)
  885. 880 VWindows.ClearPart( Rec.WindowHandle, Rec.Col1,
  886. 881 TheRow, Rec.Col2, TheRow);
  887. 882 AddCLCount( Numbers.Li(-delsize), -1, NumTypes.L0, 0);
  888. 883 MoveVerticallyTo( TLine - 1 );
  889. 884 ELSE
  890. 885 (*This is the only line *)
  891. 886 GenLists.ListInsert( '', GenLists.StrCode, TheList, 1);
  892. 887 VWindows.ClearPart( Rec.WindowHandle, Rec.Col1,
  893. 888 TheRow, Rec.Col2, TheRow);
  894. 889 MoveAcrossTo( 0 );
  895. 890 AddCLCount( Numbers.Li(2 - delsize), 0,
  896. 891 Numbers.Li(1 - INTEGER( TCharCnt.locard)), 0);
  897. 892 END;
  898. 893 END DeleteALine;
  899. 894
  900. 895 PROCEDURE JoinLines();
  901. 896 (* joins this line to the previous one
  902. 897 (caused by a BSP in the first column or a del at the end) *)
  903. 898 VAR
  904. 899 addedtoend, firstleng : INTEGER;
  905. 900 tmpsize: CARDINAL;
  906. 901 tmpadr: SYSTEM.ADDRESS;
  907. 902 OnBlankLine : BOOLEAN;
  908. 903 BEGIN
  909. 904 IF TLine = 1 THEN
  910. 905 (* if this isn't the first line *)
  911. 906 RETURN;
  912. 907 END;
  913. 908 OnBlankLine := TheLength() = 0;
  914. 909 MoveAcrossTo( 0 );
  915. 910 GenLists.GetElmtAdr( TheList, TLine - 1, tmpadr, tmpsize, DumType);
  916. 911 firstleng := ListUtils.ElmtSize( TheList, TLine - 1 );
  917. 912 IF (firstleng # 0) AND (ByteFiddler.PeekChar(LowLevel.AddAddr(tmpadr,
  918. 913 firstleng - 1)) # blank[0]) THEN
  919. 914 (* if need a space at end of prior line to separate *)
  920. 915 ListUtils.InsertIntoElmt( TheList, TLine - 1,
  921. 916 SYSTEM.ADR(blank), 1, 65535 );
  922. 917 (*append a blank to end of previous line*)
  923. 918 addedtoend := 1;
  924. 919 ELSE
  925. 920 addedtoend := 0;
  926. 921 END;
  927. 922 AddCLCount( Numbers.Li(addedtoend), 0, Numbers.Li(addedtoend), 0 );
  928. 923 (*update char counts so that MoveTo procedures will count
  929. 924 correctly as line boundary is crossed.*)
  930. 925 MoveVerticallyTo( TLine - 1 );
  931. 926 (*This changes TLine.*)
  932. 927 MoveAcrossTo( TheLength() );
  933. 928 IF NOT OnBlankLine THEN
  934. 929 GenLists.GetElmtAdr( TheList, TLine + 1, tmpadr,
  935. 930 tmpsize, DumType );
  936. 931 ListUtils.InsertIntoElmt( TheList, TLine, tmpadr,
  937. 932 tmpsize, 65535 );
  938. 933 AddCLCount( -NumTypes.L2, -1, -NumTypes.L2, 0 );
  939. 934 (*account for deletion of CR/LF and TLine*)
  940. 935 ELSE
  941. 936 AddCLCount( -NumTypes.L2, -1, NumTypes.L0, 0 );
  942. 937 (*We've lost a line, but we're past the CR/LF
  943. 938 on the line above*)
  944. 939 END;
  945. 940 GenLists.ListDelete( TheList, TLine + 1, 1);
  946. 941 WriteStrings( TLine, TheRow, TheRow );
  947. 942 ScrollRegion( TheRow + 1, Rec.Row2, 1 );
  948. 943 END JoinLines;
  949. 944
  950. 945
  951. 946 PROCEDURE NewLine();
  952. 947 VAR
  953. 948 prvadr: SYSTEM.ADDRESS;
  954. 949 OldNdx, prvsize : CARDINAL;
  955. 950 BEGIN
  956. 951 IF NOT CheckMax() THEN
  957. 952 RETURN;
  958. 953 END;
  959. 954 OldNdx := TheNdx;
  960. 955 MoveAcrossTo( 0 );
  961. 956 GenLists.GetElmtAdr( TheList, TLine, prvadr, prvsize, DumType);
  962. 957 prvsize := ListUtils.ElmtSize( TheList, TLine );
  963. 958 (*Reduces prvsize to number of bytes before the 0C.*)
  964. 959 GenLists.ListInsert( '', GenLists.StrCode, TheList, TLine + 1 );
  965. 960 IF OldNdx = 0 THEN
  966. 961 AddCLCount( NumTypes.L2, 1, NumTypes.L2, 0 );
  967. 962 (*Increment char total for the new CR/LF, and increment the
  968. 963 char position because MoveVerticallyTo won't count the
  969. 964 trailing CR/LF in this case--it thinks we've already
  970. 965 skipped it.*)
  971. 966 ELSE
  972. 967 AddCLCount( NumTypes.L2, 1, NumTypes.L0, 0 );
  973. 968 (*Increment char total for the new CR/LF.*)
  974. 969 END;
  975. 970 IF OldNdx < prvsize THEN
  976. 971 ListUtils.InsertIntoElmt( TheList, TLine + 1,
  977. 972 LowLevel.AddAddr(prvadr, OldNdx), prvsize - OldNdx, 0 );
  978. 973 ByteFiddler.PokeChar( 0C, LowLevel.AddAddr(prvadr, OldNdx) );
  979. 974 END;
  980. 975 WriteStrings( TLine, TheRow, TheRow );
  981. 976 IF TheRow < Rec.Row2 THEN
  982. 977 ScrollRegion( TheRow + 1, Rec.Row2, -1 );
  983. 978 END;
  984. 979 MoveVerticallyTo( TLine + 1 );
  985. 980 END NewLine;
  986. 981
  987. 982
  988. 983 PROCEDURE NextWord();
  989. 984 VAR
  990. 985 tmpcol, leng : INTEGER;
  991. 986 tmpsize: CARDINAL;
  992. 987 txtadr, tmpadr: SYSTEM.ADDRESS;
  993. 988 BEGIN
  994. 989 leng := ListUtils.ElmtSize( TheList, TLine );
  995. 990 IF TheNdx + 1 >= CARDINAL(leng) THEN
  996. 991 MoveVerticallyTo( TLine + 1 );
  997. 992 GenLists.GetElmtAdr( TheList, TLine, txtadr, tmpsize, DumType);
  998. 993 MoveAcrossTo(0);
  999. 994 IF ByteFiddler.PeekChar(txtadr) # blank[0] THEN
  1000. 995 RETURN;
  1001. 996 END;
  1002. 997 END;
  1003. 998 GenLists.GetElmtAdr( TheList, TLine, txtadr, tmpsize, DumType);
  1004. 999 tmpcol := TheNdx;
  1005. 1000 LOOP
  1006. 1001 tmpadr := LowLevel.AddAddr( txtadr, tmpcol );
  1007. 1002 IF tmpcol + 1 < leng THEN
  1008. 1003 IF ByteFiddler.PeekChar(tmpadr) = blank[0] THEN
  1009. 1004 LowLevel.IncAddr( tmpadr, 1 );
  1010. 1005 dumint := LowLevel.ScanNE(leng - tmpcol - 1, blank, tmpadr);
  1011. 1006 MoveAcrossTo(tmpcol + 1 + dumint);
  1012. 1007 RETURN;
  1013. 1008 ELSE
  1014. 1009 INC(tmpcol);
  1015. 1010 END;
  1016. 1011 ELSE
  1017. 1012 MoveAcrossTo(leng);
  1018. 1013 RETURN;
  1019. 1014 END;
  1020. 1015 END;
  1021. 1016 END NextWord;
  1022. 1017
  1023. 1018 PROCEDURE LastWord();
  1024. 1019 VAR
  1025. 1020 tmpcol : INTEGER;
  1026. 1021 tmpsize: CARDINAL;
  1027. 1022 txtadr, tmpadr: SYSTEM.ADDRESS;
  1028. 1023 BEGIN
  1029. 1024 tmpcol := TheNdx;
  1030. 1025 GenLists.GetElmtAdr( TheList, TLine, txtadr, tmpsize, DumType);
  1031. 1026 LOOP
  1032. 1027 IF tmpcol > 0 THEN
  1033. 1028 tmpadr := LowLevel.AddAddr(txtadr, tmpcol - 1);
  1034. 1029 IF ByteFiddler.PeekChar(tmpadr) # blank[0] THEN
  1035. 1030 dumint := LowLevel.ScanEQ(-tmpcol,blank,tmpadr);
  1036. 1031 (* last is + since scan returns neg.*)
  1037. 1032 MoveAcrossTo( tmpcol + dumint);
  1038. 1033 EXIT;
  1039. 1034 ELSE
  1040. 1035 DEC( tmpcol);
  1041. 1036 END;
  1042. 1037 ELSE
  1043. 1038 MoveVerticallyTo( TLine - 1 );
  1044. 1039 MoveAcrossTo( TheLength() );
  1045. 1040 EXIT;
  1046. 1041 END;
  1047. 1042 END;
  1048. 1043 END LastWord;
  1049. 1044
  1050. 1045 PROCEDURE KeyResponse();
  1051. 1046 VAR
  1052. 1047 OvrStr : ARRAY [0..10] OF CHAR;
  1053. 1048 SavedFore, SavedBack : MsColors.AColor;
  1054. 1049 SavedAttr : MsColors.AMonoAttribute;
  1055. 1050 BEGIN
  1056. 1051 LOOP
  1057. 1052 Rec.EdLastKey := KbdInput.KeyHit( KbdInput.AnyKeyNum );
  1058. 1053 IF Rec.FrameRec # NIL THEN
  1059. 1054 UpdateFrameRec();
  1060. 1055 UserOps.TheKeyHandler( Rec.FrameRec, Rec.EdLastKey, Rec.NextFrame );
  1061. 1056 IF Rec.overwriting THEN
  1062. 1057 VWindows.SetCursorHeight( Rec.WindowHandle, 2);
  1063. 1058 ELSE
  1064. 1059 VWindows.SetCursorHeight( Rec.WindowHandle, 4);
  1065. 1060 END;
  1066. 1061 SetAttribOrColor( Rec.EntryForeColor, Rec.EntryBackColor,
  1067. 1062 Rec.EntryAttrib );
  1068. 1063 GetFrameRecData();
  1069. 1064 END;
  1070. 1065 IF (Rec.EdLastKey = UserOps.SubmitKey)
  1071. 1066 OR (Rec.EdLastKey = UserOps.BackupKey)
  1072. 1067 OR (Rec.EdLastKey = UserOps.ExitKey) THEN
  1073. 1068 EXIT;
  1074. 1069 END;
  1075. 1070 CASE Rec.EdLastKey OF
  1076. 1071 Key.Up : (*up arrow*)
  1077. 1072 IF (TLine = 1) AND
  1078. 1073 BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1079. 1074 (*We're letting the user exit from the editor
  1080. 1075 window by pressing the up arrow on the top line
  1081. 1076 of the file.*)
  1082. 1077 EXIT;
  1083. 1078 ELSE
  1084. 1079 MoveVerticallyTo( TLine - 1 );
  1085. 1080 END;
  1086. 1081 | Key.Down : (*down arrow*)
  1087. 1082 IF (TLine = GenLists.ListLength(TheList)) AND
  1088. 1083 BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1089. 1084 (*We're letting the user exit from the editor
  1090. 1085 window by pressing the down arrow on the
  1091. 1086 bottom line of the file.*)
  1092. 1087 EXIT;
  1093. 1088 ELSE
  1094. 1089 MoveVerticallyTo( TLine + 1 );
  1095. 1090 END;
  1096. 1091 | Key.Left: (*left arrow*)
  1097. 1092 IF TheNdx>0 THEN
  1098. 1093 MoveAcrossTo(TheNdx - 1);
  1099. 1094 ELSIF BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1100. 1095 (*We're letting the user exit from the editor
  1101. 1096 window by pressing the left arrow on the
  1102. 1097 left edge of the window.*)
  1103. 1098 EXIT;
  1104. 1099 ELSIF (TheRow # Rec.Row1) THEN
  1105. 1100 MoveVerticallyTo( TLine - 1 );
  1106. 1101 MoveAcrossTo( TheLength());
  1107. 1102 END;
  1108. 1103 | Key.Right: (*right arrow*)
  1109. 1104 IF TheNdx < TheLength() THEN
  1110. 1105 MoveAcrossTo( TheNdx + 1);
  1111. 1106 ELSIF BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1112. 1107 (*We're letting the user exit from the editor
  1113. 1108 window by pressing the right arrow at the end
  1114. 1109 of the current line.*)
  1115. 1110 EXIT;
  1116. 1111 ELSIF (TLine # GenLists.ListLength( TheList)) THEN
  1117. 1112 MoveVerticallyTo( TLine + 1 );
  1118. 1113 MoveAcrossTo(0);
  1119. 1114 END;
  1120. 1115 | Key.Tab, Key.CtrlRight: (*Tab and Ctrl-RightArrow*)
  1121. 1116 IF TheNdx < TheLength() THEN
  1122. 1117 NextWord();
  1123. 1118 ELSIF BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1124. 1119 (*We're letting the user exit from the editor
  1125. 1120 window by pressing the Tab or Ctrl-RightArrow if
  1126. 1121 they're in the FieldExitKeySet.*)
  1127. 1122 EXIT;
  1128. 1123 ELSE
  1129. 1124 NextWord();
  1130. 1125 END;
  1131. 1126 | Key.BackTab, Key.CtrlLeft: (*BackTab and Ctrl-LeftArrow*)
  1132. 1127 IF TheNdx>0 THEN
  1133. 1128 LastWord();
  1134. 1129 ELSIF BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1135. 1130 EXIT;
  1136. 1131 ELSE
  1137. 1132 LastWord();
  1138. 1133 END;
  1139. 1134 | Key.F4 :
  1140. 1135 NextWord();
  1141. 1136 | Key.Ins :
  1142. 1137 IF NOT Rec.ReadOnly THEN
  1143. 1138 Rec.overwriting := NOT Rec.overwriting;
  1144. 1139 IF Rec.overwriting THEN
  1145. 1140 VWindows.SetCursorHeight( Rec.WindowHandle, 2 );
  1146. 1141 ELSE
  1147. 1142 VWindows.SetCursorHeight( Rec.WindowHandle, 4 );
  1148. 1143 END;
  1149. 1144 IF Rec.FrameRec # NIL THEN
  1150. 1145 SavedFore := VWindows.ForeColor( Rec.WindowHandle );
  1151. 1146 SavedBack := VWindows.BackColor( Rec.WindowHandle );
  1152. 1147 SavedAttr := VWindows.MonoAttr( Rec.WindowHandle );
  1153. 1148 SetPromptColors( Rec.FrameRec );
  1154. 1149 END;
  1155. 1150 IF Rec.DoCounting THEN
  1156. 1151 OvrOrIns( OvrStr);
  1157. 1152 VWindows.DrawStr( Rec.WindowHandle, 71, Rec.CountRow,
  1158. 1153 SYSTEM.ADR(OvrStr), M2Strings.Length(OvrStr) );
  1159. 1154 END;
  1160. 1155 IF Rec.FrameRec # NIL THEN
  1161. 1156 VWindows.SetForeColor( Rec.WindowHandle, SavedFore );
  1162. 1157 VWindows.SetBackColor( Rec.WindowHandle, SavedBack );
  1163. 1158 VWindows.SetMonoAttr( Rec.WindowHandle, SavedAttr );
  1164. 1159 END;
  1165. 1160 VWindows.GotoXY( Rec.WindowHandle,
  1166. 1161 Rec.Col1 + TheNdx - ColsScrolled, TheRow);
  1167. 1162 END;
  1168. 1163 | Key.Del :
  1169. 1164 IF NOT Rec.ReadOnly THEN
  1170. 1165 Rec.ChangeMade := TRUE;
  1171. 1166 IF TheNdx < TheLength() THEN
  1172. 1167 DeleteAChar(0);
  1173. 1168 ELSE
  1174. 1169 MoveVerticallyTo( TLine + 1 );
  1175. 1170 MoveAcrossTo( 0 );
  1176. 1171 JoinLines();
  1177. 1172 END;
  1178. 1173 END;
  1179. 1174 | Key.Home:
  1180. 1175 (* go to start of current line*)
  1181. 1176 MoveAcrossTo(0);
  1182. 1177 | Key.AltD :
  1183. 1178 IF NOT Rec.ReadOnly THEN
  1184. 1179 Rec.ChangeMade := TRUE;
  1185. 1180 DeleteALine();
  1186. 1181 END;
  1187. 1182 | Key.AltI, Key.AltU :
  1188. 1183 IF NOT Rec.ReadOnly THEN
  1189. 1184 Rec.ChangeMade := TRUE;
  1190. 1185 InsertDeleteBuffer();
  1191. 1186 END;
  1192. 1187 | Key.End: (*End*)
  1193. 1188 (* go to end of current line*)
  1194. 1189 MoveAcrossTo( TheLength());
  1195. 1190 | Key.PgUp: (*PgUp*)
  1196. 1191 IF (TLine = 1) AND
  1197. 1192 BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1198. 1193 (*We're letting the user exit from the editor
  1199. 1194 window by pressing PgUp on the top line
  1200. 1195 of the file.*)
  1201. 1196 EXIT;
  1202. 1197 ELSE
  1203. 1198 PageUp();
  1204. 1199 (* go up one page *)
  1205. 1200 END;
  1206. 1201 | Key.PgDn: (*PgDn*)
  1207. 1202 IF (TLine = GenLists.ListLength(TheList)) AND
  1208. 1203 BigSets.InSet( UserOps.FieldExitKeySet, Rec.EdLastKey ) THEN
  1209. 1204 (*We're letting the user exit from the editor
  1210. 1205 window by pressing the PgDn key on the
  1211. 1206 bottom line of the file.*)
  1212. 1207 EXIT;
  1213. 1208 ELSE
  1214. 1209 PageDown();
  1215. 1210 (* go down one page *)
  1216. 1211 END;
  1217. 1212 | Key.CtrlPgUp:
  1218. 1213 (* go to top of file *)
  1219. 1214 MoveVerticallyTo( 1 );
  1220. 1215 | Key.CtrlPgDn:
  1221. 1216 (* go to end of text file *)
  1222. 1217 MoveVerticallyTo( GenLists.ListLength(TheList) );
  1223. 1218 MoveAcrossTo( TheLength() );
  1224. 1219 | Key.F7:
  1225. 1220 (* pack paragraphs starting at current line and going
  1226. 1221 down until indentation changes *)
  1227. 1222 IF (Rec.Wrapping) AND (NOT Rec.ReadOnly) THEN
  1228. 1223 Rec.ChangeMade := TRUE;
  1229. 1224 Reformat();
  1230. 1225 END;
  1231. 1226 | Key.F7 + Key.FShift:
  1232. 1227 (*ShiftF7 toggles between wrapping and not wrapping.*)
  1233. 1228 Rec.Wrapping := NOT Rec.Wrapping;
  1234. 1229 IF Rec.Wrapping AND (NOT Rec.ReadOnly) THEN
  1235. 1230 Rec.ChangeMade := TRUE;
  1236. 1231 Reformat();
  1237. 1232 END;
  1238. 1233 | Key.F8:
  1239. 1234 Testing := NOT Testing;
  1240. 1235 | Key.BackSpace :
  1241. 1236 IF NOT Rec.ReadOnly THEN
  1242. 1237 Rec.ChangeMade := TRUE;
  1243. 1238 IF TheNdx>0 THEN
  1244. 1239 DeleteAChar(1);
  1245. 1240 ELSE
  1246. 1241 JoinLines();
  1247. 1242 END;
  1248. 1243 END;
  1249. 1244 | Key.Return :
  1250. 1245 IF NOT Rec.ReadOnly THEN
  1251. 1246 Rec.ChangeMade := TRUE;
  1252. 1247 NewLine();
  1253. 1248 END;
  1254. 1249 ELSE
  1255. 1250 IF (NOT Rec.ReadOnly) AND (Rec.EdLastKey # 0)
  1256. 1251 AND (Rec.EdLastKey < KbdInput.Extended) THEN
  1257. 1252 Rec.ChangeMade := TRUE;
  1258. 1253 ReplaceWith( CHR(Rec.EdLastKey) );
  1259. 1254 END;
  1260. 1255 END;
  1261. 1256 END;
  1262. 1257 END KeyResponse;
  1263. 1258
  1264. 1259 VAR
  1265. 1260 SavedHeight, BxCol1, BxCol2, BxRow1, BxRow2 : CARDINAL;
  1266. 1261
  1267. 1262 BEGIN (*DefaultEditor*)
  1268. 1263 GetFrameRecData();
  1269. 1264 Rec.ChangeMade := FALSE;
  1270. 1265 IF Rec.Col2 < Rec.Col1 THEN
  1271. 1266 INC(Rec.Col2, Rec.Col1);
  1272. 1267 END;
  1273. 1268 ColsScrolled := 0;
  1274. 1269 LastLineDeleted := 0;
  1275. 1270 Rec.Col1 := Numbers.Between(1, Rec.Col1, DisplayLeng);
  1276. 1271 Rec.Row1 := Numbers.Between(1, Rec.Row1, Rec.Row2);
  1277. 1272 Rec.Row2 := Numbers.Between(Rec.Row1, Rec.Row2,
  1278. 1273 VWindows.EndRow(Rec.WindowHandle));
  1279. 1274 Rec.Col2 := Numbers.Between(Rec.Col1, Rec.Col2, DisplayLeng);
  1280. 1275 BxCol1 := Rec.Col1;
  1281. 1276 BxCol2 := Rec.Col2;
  1282. 1277 BxRow1 := Rec.Row1;
  1283. 1278 BxRow2 := Rec.Row2;
  1284. 1279 IF Rec.FrameRec # NIL THEN
  1285. 1280 SavedHeight := VWindows.GetCursorHeight( Rec.FrameRec^.WindowHandle );
  1286. 1281 END;
  1287. 1282 SetAttribOrColor( Rec.EntryForeBox, Rec.EntryBackBox, Rec.EntryAttrib );
  1288. 1283 CASE Rec.EntryBox OF
  1289. 1284 (* Draw Entry Box *)
  1290. 1285 2:
  1291. 1286 VWindows.DrawBox( Rec.WindowHandle,
  1292. 1287 VWindows.DoubleBox, Rec.Col1, Rec.Row1, Rec.Col2,
  1293. 1288 Rec.Row2);
  1294. 1289 | 1:
  1295. 1290 VWindows.DrawBox( Rec.WindowHandle,
  1296. 1291 VWindows.SingleBox, Rec.Col1, Rec.Row1, Rec.Col2,
  1297. 1292 Rec.Row2);
  1298. 1293 ELSE (*do nothing*);
  1299. 1294 END;
  1300. 1295 IF (Rec.EntryBox # 0) OR (Rec.ExitBox # 0) THEN
  1301. 1296 (* Correct coordinates to the area inside the box *)
  1302. 1297 INC(Rec.Col1);
  1303. 1298 INC(Rec.Row1);
  1304. 1299 DEC(Rec.Row2);
  1305. 1300 DEC(Rec.Col2);
  1306. 1301 END;
  1307. 1302 IF Rec.DoCounting AND (Rec.Row2 >= Rec.CountRow) THEN
  1308. 1303 Rec.Row2 := Numbers.Min( Rec.Row2, Rec.CountRow - 1 );
  1309. 1304 (*This makes sure Row2 doesn't interfere with the
  1310. 1305 prompt line.*)
  1311. 1306 END;
  1312. 1307 WindowHeight := Rec.Row2 - Rec.Row1 + 1;
  1313. 1308 Rec.TextRow1 := Numbers.Between(1, Rec.TextRow1,
  1314. 1309 GenLists.ListLength(TheList));
  1315. 1310 Rec.CursorCol := Numbers.Between(1, Rec.CursorCol,
  1316. 1311 (Rec.Col2 - Rec.Col1) + 1 );
  1317. 1312 Rec.CursorRow := Numbers.Between(1, Rec.CursorRow,
  1318. 1313 WindowHeight );
  1319. 1314 Rec.CursorRow := Numbers.Between(1, Rec.CursorRow,
  1320. 1315 GenLists.ListLength(TheList) + 1 - Rec.TextRow1 );
  1321. 1316 (*We correct Rec.CursorRow again to prevent it from falling
  1322. 1317 below the bottom of TheList. Added 16 Nov 86.*)
  1323. 1318 SetAttribOrColor( Rec.EntryForeColor, Rec.EntryBackColor,
  1324. 1319 Rec.EntryAttrib );
  1325. 1320 MaxLength := (Rec.Col2 - Rec.Col1) + 1;
  1326. 1321 LowLevel.Fill( SYSTEM.ADR(BlankStr), DisplayLeng + 1, blank);
  1327. 1322 Testing := FALSE;
  1328. 1323 IF GenLists.ListLength( TheList) # 0 THEN
  1329. 1324 WriteStrings( Rec.TextRow1, Rec.Row1, Rec.Row2);
  1330. 1325 TLine := Rec.TextRow1 + Rec.CursorRow - 1;
  1331. 1326 ELSE
  1332. 1327 (* set counter to line one and clear window *)
  1333. 1328 GenLists.ListInsert( '', GenLists.StrCode, TheList, 1);
  1334. 1329 TLine := 1;
  1335. 1330 VWindows.ClearPart( Rec.WindowHandle, Rec.Col1,
  1336. 1331 Rec.Row1, Rec.Col2, Rec.Row2);
  1337. 1332 END;
  1338. 1333 TheRow := Rec.CursorRow + Rec.Row1 - 1;
  1339. 1334 TheNdx := Rec.CursorCol - 1;
  1340. 1335 CountChars( 1, RCharCnt.longi, RLineCnt, TLine, TCharCnt.longi);
  1341. 1336 TCharCnt.longi := TCharCnt.longi + Numbers.Lc( TheNdx );
  1342. 1337 IF Rec.DoCounting THEN
  1343. 1338 WriteFooter();
  1344. 1339 ELSE
  1345. 1340 RCharCnt.longi := NumTypes.L1;
  1346. 1341 RLineCnt := 1;
  1347. 1342 TCharCnt.longi := NumTypes.L1;
  1348. 1343 END;
  1349. 1344 VWindows.GotoXY( Rec.WindowHandle, Rec.Col1 +
  1350. 1345 TheNdx - ColsScrolled, TheRow);
  1351. 1346 IF Rec.overwriting THEN
  1352. 1347 VWindows.SetCursorHeight( Rec.WindowHandle, 2);
  1353. 1348 ELSE
  1354. 1349 VWindows.SetCursorHeight( Rec.WindowHandle, 4);
  1355. 1350 END;
  1356. 1351 KeyResponse();
  1357. 1352 Rec.CursorRow := (TheRow + 1) - Rec.Row1;
  1358. 1353 Rec.CursorCol := 1 + TheNdx;
  1359. 1354 Rec.TextRow1 := TLine + 1 - Rec.CursorRow;
  1360. 1355 DoExitBox := ( Rec.ExitBox # Rec.EntryBox) OR
  1361. 1356 ( Rec.ExitForeBox # Rec.EntryForeBox) OR
  1362. 1357 ( Rec.ExitBackBox # Rec.EntryBackBox) OR
  1363. 1358 ( Rec.ExitAttrib # Rec.EntryAttrib);
  1364. 1359 (* whether the exit box differs from the entry, and so must
  1365. 1360 be re-drawn *)
  1366. 1361 IF DoExitBox THEN
  1367. 1362 SetAttribOrColor( Rec.ExitForeBox, Rec.ExitBackBox, Rec.ExitAttrib );
  1368. 1363 CASE Rec.ExitBox OF
  1369. 1364 2:
  1370. 1365 VWindows.DrawBox( Rec.WindowHandle,
  1371. 1366 VWindows.DoubleBox, BxCol1, BxRow1, BxCol2,
  1372. 1367 BxRow2);
  1373. 1368 | 1:
  1374. 1369 VWindows.DrawBox( Rec.WindowHandle,
  1375. 1370 VWindows.SingleBox, BxCol1, BxRow1, BxCol2,
  1376. 1371 BxRow2);
  1377. 1372 ELSE
  1378. 1373 VWindows.ClearPart( Rec.WindowHandle,
  1379. 1374 BxCol1, BxRow1, BxCol2, BxRow2);
  1380. 1375 END;
  1381. 1376 END;
  1382. 1377 SetAttribOrColor( Rec.ExitForeColor, Rec.ExitBackColor,
  1383. 1378 Rec.ExitAttrib );
  1384. 1379 IF (Rec.EntryForeColor # Rec.ExitForeColor) OR
  1385. 1380 (Rec.EntryBackColor # Rec.ExitBackColor) OR
  1386. 1381 (Rec.EntryAttrib # Rec.ExitAttrib) OR
  1387. 1382 (DoExitBox AND ( Rec.ExitBox = 0)) THEN
  1388. 1383 WriteStrings( TLine - (TheRow - Rec.Row1), Rec.Row1, Rec.Row2);
  1389. 1384 (* Rewrite the current screen *)
  1390. 1385 END;
  1391. 1386 IF (Rec.EntryBox # 0) OR (Rec.ExitBox # 0) THEN
  1392. 1387 (* Set coordinates back to area that includes box *)
  1393. 1388 DEC(Rec.Col1);
  1394. 1389 DEC(Rec.Row1);
  1395. 1390 INC(Rec.Row2);
  1396. 1391 INC(Rec.Col2);
  1397. 1392 END;
  1398. 1393 UpdateFrameRec();
  1399. 1394 IF Rec.FrameRec # NIL THEN
  1400. 1395 VWindows.SetCursorHeight( Rec.FrameRec^.WindowHandle, SavedHeight );
  1401. 1396 END;
  1402. 1397 END DefaultEditor;
  1403. 1398
  1404. 1399
  1405. 1400 PROCEDURE SetGlobals( VAR Rec: VEditor.AnEdControlRec );
  1406. 1401 BEGIN
  1407. 1402 overwriting := Rec.overwriting;
  1408. 1403 DoCounting := Rec.DoCounting;
  1409. 1404 MaxLines := Rec.MaxLines;
  1410. 1405 EdLastKey := Rec.EdLastKey;
  1411. 1406 ExitBox := Rec.ExitBox;
  1412. 1407 EntryBox := Rec.EntryBox;
  1413. 1408 CountRow := Rec.CountRow;
  1414. 1409 EdPromptFore := Rec.EdPromptFore;
  1415. 1410 EdPromptBack := Rec.EdPromptBack;
  1416. 1411 EdPromptAttrib := Rec.EdPromptAttrib;
  1417. 1412 EntryAttrib := Rec.EntryAttrib;
  1418. 1413 ExitAttrib := Rec.ExitAttrib;
  1419. 1414 EntryForeColor := Rec.EntryForeColor;
  1420. 1415 EntryBackColor := Rec.EntryBackColor;
  1421. 1416 ExitForeColor := Rec.ExitForeColor;
  1422. 1417 ExitBackColor := Rec.ExitBackColor;
  1423. 1418 EntryForeBox := Rec.EntryForeBox;
  1424. 1419 EntryBackBox := Rec.EntryBackBox;
  1425. 1420 ExitForeBox := Rec.ExitForeBox;
  1426. 1421 ExitBackBox := Rec.ExitBackBox;
  1427. 1422 END SetGlobals;
  1428. 1423
  1429. 1424
  1430. 1425 PROCEDURE GetGlobals( VAR Rec: VEditor.AnEdControlRec );
  1431. 1426 BEGIN
  1432. 1427 Rec.overwriting := overwriting;
  1433. 1428 Rec.DoCounting := DoCounting;
  1434. 1429 Rec.MaxLines := MaxLines;
  1435. 1430 Rec.ExitBox := ExitBox;
  1436. 1431 Rec.EntryBox := EntryBox;
  1437. 1432 Rec.CountRow := CountRow;
  1438. 1433 Rec.EdPromptFore := EdPromptFore;
  1439. 1434 Rec.EdPromptBack := EdPromptBack;
  1440. 1435 Rec.EdPromptAttrib := EdPromptAttrib;
  1441. 1436 Rec.EntryAttrib := EntryAttrib;
  1442. 1437 Rec.ExitAttrib := ExitAttrib;
  1443. 1438 Rec.EntryForeColor := EntryForeColor;
  1444. 1439 Rec.EntryBackColor := EntryBackColor;
  1445. 1440 Rec.ExitForeColor := ExitForeColor;
  1446. 1441 Rec.ExitBackColor := ExitBackColor;
  1447. 1442 Rec.EntryForeBox := EntryForeBox;
  1448. 1443 Rec.EntryBackBox := EntryBackBox;
  1449. 1444 Rec.ExitForeBox := ExitForeBox;
  1450. 1445 Rec.ExitBackBox := ExitBackBox;
  1451. 1446 END GetGlobals;
  1452. 1447
  1453. 1448 VAR
  1454. 1449 GlobalEdRec: VEditor.AnEdControlRec;
  1455. 1450
  1456. 1451 PROCEDURE ScrnEdit(Col1, Row1, Col2, Row2 : CARDINAL;
  1457. 1452 VAR TheList : GenLists.GenList; VAR TextRow1, CursorCol,
  1458. 1453 CursorRow: CARDINAL; VAR ChangeMade: BOOLEAN;
  1459. 1454 ReadOnly: BOOLEAN; VAR FrameRec: ScrnTypes.DisplayFrame): INTEGER;
  1460. 1455 VAR
  1461. 1456 LocalRec : VEditor.AnEdControlRec;
  1462. 1457 tmpint: INTEGER;
  1463. 1458 BEGIN
  1464. 1459 VEditor.InitEdRec( LocalRec );
  1465. 1460 GetGlobals( LocalRec );
  1466. 1461 LocalRec.Wrapping := FALSE;
  1467. 1462 LocalRec.NextFrame := '';
  1468. 1463 LocalRec.Col1 := Col1;
  1469. 1464 LocalRec.Row1 := Row1;
  1470. 1465 LocalRec.Col2 := Col2;
  1471. 1466 LocalRec.Row2 := Row2;
  1472. 1467 LocalRec.TextRow1 := TextRow1;
  1473. 1468 LocalRec.CursorCol := CursorCol;
  1474. 1469 LocalRec.CursorRow := CursorRow;
  1475. 1470 LocalRec.ChangeMade := ChangeMade;
  1476. 1471 LocalRec.ReadOnly := ReadOnly;
  1477. 1472 LocalRec.FrameRec := FrameRec;
  1478. 1473 DefaultEditor( TheList, LocalRec );
  1479. 1474 TextRow1 := LocalRec.TextRow1;
  1480. 1475 CursorCol := LocalRec.CursorCol;
  1481. 1476 CursorRow := LocalRec.CursorRow;
  1482. 1477 ChangeMade := LocalRec.ChangeMade;
  1483. 1478 IF StrConv.StrToInteger( LocalRec.NextFrame, 0, tmpint ) THEN
  1484. 1479 RETURN tmpint;
  1485. 1480 ELSE
  1486. 1481 RETURN 0;
  1487. 1482 END;
  1488. 1483 END ScrnEdit;
  1489. 1484
  1490. 1485 PROCEDURE Init();
  1491. 1486 BEGIN
  1492. 1487 IF Initialized THEN
  1493. 1488 RETURN;
  1494. 1489 ELSE
  1495. 1490 Initialized := TRUE;
  1496. 1491 END;
  1497. 1492 (*EntryDiag:
  1498. 1493 Diagnostics.Init();
  1499. 1494 :EntryDiag*)
  1500. 1495
  1501. 1496 BigSets.Init();
  1502. 1497 ByteFiddler.Init();
  1503. 1498 GenLists.Init();
  1504. 1499 KbdInput.Init();
  1505. 1500 Key.Init();
  1506. 1501 ListUtils.Init();
  1507. 1502 LowLevel.Init();
  1508. 1503 M2Strings.Init();
  1509. 1504 MsColors.Init();
  1510. 1505 Numbers.Init();
  1511. 1506 NumTypes.Init();
  1512. 1507 PosUtils.Init();
  1513. 1508 ScrnTypes.Init();
  1514. 1509 ScrnUtl1.Init();
  1515. 1510 Spkr.Init();
  1516. 1511 StrConv.Init();
  1517. 1512 StrEdit.Init();
  1518. 1513 UserOps.Init();
  1519. 1514 VEditor.Init();
  1520. 1515 VWindows.Init();
  1521. 1516 (*EntryDiag:
  1522. 1517 Diagnostics.diagS( 'Entering Editor', '' );
  1523. 1518 :EntryDiag*)
  1524. 1519
  1525. 1520 VEditor.InitEdRec( GlobalEdRec );
  1526. 1521 SetGlobals( GlobalEdRec );
  1527. 1522 blank[0] := ' ';
  1528. 1523 GenLists.NilList( DeleteBuffer );
  1529. 1524
  1530. 1525 (*EntryDiag:
  1531. 1526 Diagnostics.diagS( 'Exiting Editor', '' );
  1532. 1527 :EntryDiag*)
  1533. 1528 END Init;
  1534. 1529
  1535. 1530 BEGIN
  1536. 1531 Initialized := FALSE;
  1537. 1532 Init();
  1538. 1533 END Editor.
  1539. 4 errors