SCRNUTL2.MOD 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. IMPLEMENTATION MODULE ScrnUtl2;
  2. (*
  3. * REPERTOIRE
  4. * Release 1.6
  5. * By Charles Bradford and Cole Brecheen
  6. * (c) Copyright 1985-1992 PMI
  7. * Green Bay, Wisconsin
  8. * All rights reserved
  9. * (414) 468-6040
  10. *
  11. * $Header: D:/logfiles/mods/scrnutl2.mov 1.5 10 Mar 1991 15:32:40 coleb $
  12. *
  13. *)
  14. (*
  15. This module contains utilities that neither ScreenDisplay nor
  16. InputManager use, but that you may find useful.
  17. *)
  18. FROM ScrnTypes IMPORT DisplayFrameRec;
  19. (*We have to import this separately because of a bug in Stony
  20. Brook M2; TSIZE doesn't take qualified identifiers.*)
  21. IMPORT ControlUtils;
  22. IMPORT DspFiles;
  23. IMPORT ErrorNames;
  24. IMPORT FrameManager;
  25. IMPORT FramePainter;
  26. IMPORT GenLists;
  27. IMPORT M2Strings;
  28. IMPORT MsColors;
  29. IMPORT Numbers;
  30. IMPORT PosUtils;
  31. IMPORT ScrnTypes;
  32. IMPORT ScrnUtl1;
  33. IMPORT SYSTEM;
  34. IMPORT VStorage;
  35. IMPORT VWindows;
  36. VAR
  37. Initialized : BOOLEAN;
  38. PROCEDURE Init();
  39. BEGIN
  40. IF Initialized THEN
  41. RETURN;
  42. ELSE
  43. Initialized := TRUE;
  44. END;
  45. ControlUtils.Init();
  46. DspFiles.Init();
  47. ErrorNames.Init();
  48. FrameManager.Init();
  49. FramePainter.Init();
  50. GenLists.Init();
  51. M2Strings.Init();
  52. MsColors.Init();
  53. Numbers.Init();
  54. PosUtils.Init();
  55. ScrnTypes.Init();
  56. ScrnUtl1.Init();
  57. VStorage.Init();
  58. VWindows.Init();
  59. END Init;
  60. CONST
  61. AfterLastElmt = 65535;
  62. PROCEDURE CloseDisplayFrame(VAR FrameRec : ScrnTypes.DisplayFrame);
  63. (* disposes of all records and pointers in use by FrameRec. *)
  64. BEGIN (* procedure CloseDisplayFrame *)
  65. ClearFrameStack(FrameRec);
  66. IF (FrameRec^.FromFile # NIL) THEN
  67. (*Remember that there may not be a DspFile associated with
  68. the frame.*)
  69. IF NOT FrameRec^.SelfSharedWithFile THEN
  70. GenLists.DisposeList( FrameRec^.self );
  71. (*We only dispose of the self list, because all the other
  72. lists are actually sublists of it. *)
  73. END;
  74. ELSE
  75. GenLists.DisposeList( FrameRec^.self );
  76. END;
  77. FrameManager.FrameDeactivated( FrameRec );
  78. VStorage.DosDealloc( FrameRec, SYSTEM.TSIZE(DisplayFrameRec));
  79. (*Note that we don't dispose of FromFile because some other
  80. frame may be pointing to it.*)
  81. END CloseDisplayFrame;
  82. PROCEDURE CopyEdField( frame1: ScrnTypes.DisplayFrame;
  83. FieldName1: ARRAY OF CHAR; frame2: ScrnTypes.DisplayFrame;
  84. FieldName2: ARRAY OF CHAR );
  85. VAR
  86. list1, list2: GenLists.GenList;
  87. BEGIN
  88. IF 0 # ScrnUtl1.FieldNum( frame1, FieldName1 ) THEN
  89. IF ScrnUtl1.ListFromEdField( frame1,
  90. frame1^.CurrentField, list1 ) THEN
  91. IF 0 # ScrnUtl1.FieldNum( frame2, FieldName2 ) THEN
  92. GenLists.CopyList( list1, list2 );
  93. IF ScrnUtl1.ListToEdField( list2, frame2,
  94. frame2^.CurrentField ) THEN
  95. RETURN;
  96. END;
  97. END;
  98. END;
  99. END;
  100. HALT();
  101. END CopyEdField;
  102. PROCEDURE CreateImageElement( VAR TheElmt: ScrnTypes.ImageElement; col,
  103. row: CARDINAL; ForeColor, BackColor: MsColors.AColor; Attrib:
  104. MsColors.AMonoAttribute; FieldNum: CARDINAL; VAR TheText: ARRAY OF
  105. CHAR);
  106. BEGIN
  107. TheElmt.row := row;
  108. TheElmt.col := col;
  109. TheElmt.foreg := ForeColor;
  110. TheElmt.backg := BackColor;
  111. TheElmt.atrb := Attrib;
  112. TheElmt.field := FieldNum;
  113. M2Strings.Assign( TheText, TheElmt.text );
  114. END CreateImageElement;
  115. PROCEDURE AddImageElement( VAR FrameRec: ScrnTypes.DisplayFrame;
  116. VAR TheElmt: ScrnTypes.ImageElement; VAR NewImageNum: CARDINAL );
  117. VAR
  118. width, LastImage, cnt, LastField: CARDINAL;
  119. FieldPtr: ScrnTypes.InputFieldPtr;
  120. BEGIN
  121. NewImageNum := 1;
  122. width := M2Strings.Length( TheElmt.text );
  123. IF NOT GenLists.Initialized( FrameRec^.ImageList ) THEN
  124. GenLists.NewList( FrameRec^.ImageList );
  125. ScrnUtl1.PutFrameLists( FrameRec );
  126. (* Make sure the new ImageList gets inserted into
  127. FrameRec's .self list. *)
  128. END;
  129. LastImage := GenLists.ListLength( FrameRec^.ImageList );
  130. (* find an image element lower than row *)
  131. WHILE (NewImageNum <= LastImage) AND
  132. (ScrnUtl1.VirtualImageRow(FrameRec, NewImageNum) <= TheElmt.row) DO
  133. INC( NewImageNum );
  134. END;
  135. IF (TheElmt.col + width - 1) > FrameRec^.VirtualWidth THEN
  136. FrameRec^.VirtualWidth := TheElmt.col + width - 1;
  137. END;
  138. IF TheElmt.row > FrameRec^.VirtualHeight THEN
  139. FrameRec^.VirtualHeight := TheElmt.row;
  140. END;
  141. ScrnUtl1.EncodeImageRec( TheElmt );
  142. IF NewImageNum > LastImage THEN
  143. (* No lower image element found, so we put it at the end of the
  144. list. *)
  145. GenLists.ListInsert( TheElmt, GenLists.StrCode,
  146. FrameRec^.ImageList, AfterLastElmt );
  147. ELSE
  148. GenLists.ListInsert( TheElmt, GenLists.StrCode,
  149. FrameRec^.ImageList, NewImageNum );
  150. (* Now we have to fix up the field list; every field
  151. with an ImageNum >= NewImageNum needs its ImageNum
  152. field incremented. *)
  153. LastField := ScrnUtl1.FieldListTotal( FrameRec );
  154. FOR cnt := 1 TO LastField DO
  155. ScrnUtl1.GetFieldPtr( FrameRec, cnt, FieldPtr );
  156. IF FieldPtr^.ImageNum >= NewImageNum THEN
  157. (* Because we're incrementing when ImageNum =
  158. NewImageNum, you have to add to the ImageList
  159. before adding to the FieldList when you're adding
  160. a new field to a frame. *)
  161. INC( FieldPtr^.ImageNum );
  162. END;
  163. END;
  164. END;
  165. END AddImageElement;
  166. PROCEDURE WriteToFrame( VAR FrameRec: ScrnTypes.DisplayFrame; col,
  167. row: CARDINAL; text: ARRAY OF CHAR );
  168. VAR
  169. ImageNum: CARDINAL;
  170. TmpRec: ScrnTypes.ImageElement;
  171. BEGIN
  172. CreateImageElement( TmpRec, col, row, FrameRec^.normfor,
  173. FrameRec^.normbak, FrameRec^.normatrb, 0, text );
  174. AddImageElement( FrameRec, TmpRec, ImageNum );
  175. END WriteToFrame;
  176. PROCEDURE ChoiceListToFrame( TheList: GenLists.GenList; TheFrame:
  177. ScrnTypes.DisplayFrame );
  178. VAR
  179. cnt, lngth, TypeCode, col, row: CARDINAL;
  180. TmpStr: ARRAY [0..79] OF CHAR;
  181. BEGIN
  182. lngth := GenLists.ListLength( TheList );
  183. cnt := 1;
  184. col := 2;
  185. row := TheFrame^.headline + 1;
  186. IF row = 1 THEN
  187. INC( row);
  188. END;
  189. WHILE cnt <= lngth DO
  190. GenLists.GetElmt( TheList, cnt, TmpStr, TypeCode );
  191. IF TypeCode = GenLists.StrCode THEN
  192. ControlUtils.AddMenuItem( TheFrame, col, row, TmpStr,
  193. M2Strings.Length(TmpStr), 0, '' );
  194. END;
  195. INC( row );
  196. INC( cnt );
  197. END;
  198. END ChoiceListToFrame;
  199. PROCEDURE ListToFrame( TheList: GenLists.GenList; TheFrame:
  200. ScrnTypes.DisplayFrame );
  201. VAR
  202. cnt, lngth, TypeCode, col, row: CARDINAL;
  203. TmpStr: ARRAY [0..79] OF CHAR;
  204. BEGIN
  205. lngth := GenLists.ListLength( TheList );
  206. cnt := 1;
  207. col := 2;
  208. row := TheFrame^.headline + 1;
  209. IF row = 1 THEN
  210. INC( row);
  211. END;
  212. WHILE cnt <= lngth DO
  213. GenLists.GetElmt( TheList, cnt, TmpStr, TypeCode );
  214. IF TypeCode = GenLists.StrCode THEN
  215. WriteToFrame( TheFrame, col, row, TmpStr );
  216. END;
  217. INC( row );
  218. INC( cnt );
  219. END;
  220. END ListToFrame;
  221. PROCEDURE Display( TheFrame: ScrnTypes.DisplayFrame; FrameName
  222. : ARRAY OF CHAR );
  223. BEGIN
  224. IF TheFrame^.FromFile = NIL THEN
  225. ErrorNames.WarningName( 'OpnDsp' );
  226. RETURN;
  227. END;
  228. DspFiles.ReadFrame( TheFrame^.FromFile,
  229. TheFrame, FrameName );
  230. FramePainter.ShowDisplayFrame( TheFrame, 0, 0, 0, 0);
  231. END Display;
  232. PROCEDURE ReadAndShow( TheFile: ScrnTypes.DisplayFile;
  233. TheFrame: ScrnTypes.DisplayFrame; FrameName : ARRAY OF CHAR
  234. );
  235. BEGIN
  236. DspFiles.ReadFrame( TheFile, TheFrame, FrameName );
  237. FramePainter.ShowDisplayFrame( TheFrame, 0, 0, 0, 0);
  238. END ReadAndShow;
  239. PROCEDURE PushFrame( VAR FrameRec : ScrnTypes.DisplayFrame);
  240. (* Push the current frame, with its fields list, onto the
  241. frame stack for this file. The current frame will be left
  242. undefined, with no fields list linked to it; it must be
  243. filled in with a call to Display. *)
  244. VAR
  245. nodeptr : ScrnTypes.DisplayFrame;
  246. BEGIN
  247. VStorage.DosAlloc(nodeptr, SYSTEM.TSIZE(DisplayFrameRec) );
  248. nodeptr^ := FrameRec^;
  249. (* save the frame *)
  250. FrameRec^.PushedFrame := nodeptr;
  251. (* link it to the new current frame. *)
  252. GenLists.CopyList( FrameRec^.self, nodeptr^.self );
  253. (*Note that FrameRec^.self probably equals
  254. FrameRec^.FromFile^.ListBuf at this point, so we
  255. have to be careful.*)
  256. ScrnUtl1.GetFrameLists( nodeptr );
  257. (*The pushed frame's lists are now completely disconnected
  258. from FrameRec's lists.*)
  259. nodeptr^.SelfSharedWithFile := FALSE;
  260. END PushFrame;
  261. PROCEDURE CheckPushedFrame(VAR FrameRec :
  262. ScrnTypes.DisplayFrame) : ScrnTypes.DisplayFrame;
  263. (* used internally by PopFrame and PopZapFrame *)
  264. (* Returns pointer to valid pushed frame. *)
  265. VAR
  266. nodeptr : ScrnTypes.DisplayFrame;
  267. BEGIN (* procedure CheckPushedFrame *)
  268. nodeptr := FrameRec^.PushedFrame;
  269. IF nodeptr = NIL THEN
  270. ErrorNames.WarningName( 'FrmStk' );
  271. END;
  272. RETURN nodeptr;
  273. END CheckPushedFrame;
  274. PROCEDURE PopFrame(VAR FrameRec : ScrnTypes.DisplayFrame);
  275. (* Reverses the effect of PushFrame; current display file record is
  276. discarded, and the frame on the top of the stack replaces it.
  277. After PopFrame, program would usually call ControlScreen with
  278. "showfields" TRUE.*)
  279. VAR
  280. nodeptr : ScrnTypes.DisplayFrame;
  281. BEGIN
  282. nodeptr := CheckPushedFrame(FrameRec);
  283. IF NOT FrameRec^.SelfSharedWithFile THEN
  284. GenLists.DisposeList( FrameRec^.self );
  285. (* This disposes of all FrameRec's lists, because they are
  286. actually sublists of self.*)
  287. END;
  288. FrameRec^ := nodeptr^;
  289. (* restore pushed frame. *)
  290. IF GenLists.ListLength( FrameRec^.self ) > 0 THEN
  291. (*We have to do this test because we need to allow
  292. PushFrame's on frames that have been initialized but not
  293. read into; we don't have to test for uninitialized self
  294. lists because InitDisplayFrame does a NewList on it, and
  295. we can at least require FrameRec to be initialized.*)
  296. ScrnUtl1.GetFrameLists( FrameRec );
  297. (*Gets the frame's lists out of self. *)
  298. END;
  299. VStorage.DosDealloc(nodeptr, SYSTEM.TSIZE(DisplayFrameRec) );
  300. (* discard storage for pushed frame. *)
  301. END PopFrame;
  302. PROCEDURE PopZapFrame(VAR FrameRec : ScrnTypes.DisplayFrame);
  303. (*Removes last frame pushed from stack of Pushed frames, but
  304. does not change current frame or its contents. The current
  305. frame is linked to the next frame on the stack. *)
  306. VAR
  307. nodeptr : ScrnTypes.DisplayFrame;
  308. BEGIN (* procedure PopZapFrame *)
  309. nodeptr := CheckPushedFrame(FrameRec);
  310. IF NOT nodeptr^.SelfSharedWithFile THEN
  311. GenLists.DisposeList( nodeptr^.self );
  312. (* Disposes of all lists associated with pushed frame. *)
  313. END;
  314. FrameRec^.PushedFrame := nodeptr^.PushedFrame;
  315. (* link new top of stack. *)
  316. VStorage.DosDealloc(nodeptr, SYSTEM.TSIZE(DisplayFrameRec) );
  317. (* discard storage for pushed frame. *)
  318. END PopZapFrame;
  319. PROCEDURE ClearFrameStack(VAR FrameRec : ScrnTypes.DisplayFrame);
  320. (* Removes all frames from stack of Pushed frames. *)
  321. BEGIN (* procedure ClearFrameStack *)
  322. WHILE FrameRec^.PushedFrame # NIL DO
  323. PopZapFrame(FrameRec);
  324. END;
  325. END ClearFrameStack;
  326. PROCEDURE ShowMessage( TheFile: ScrnTypes.DisplayFile;
  327. FrameName : ARRAY OF CHAR );
  328. VAR
  329. TmpFrame: ScrnTypes.DisplayFrame;
  330. BEGIN
  331. ScrnTypes.InitDisplayFrame( TmpFrame, VWindows.CurrentWindow );
  332. DspFiles.ReadFrame( TheFile, TmpFrame, FrameName );
  333. FramePainter.ShowDisplayFrame( TmpFrame, 0, 0, 0, 0 );
  334. ControlUtils.Control( TmpFrame );
  335. CloseDisplayFrame( TmpFrame );
  336. END ShowMessage;
  337. PROCEDURE GetEdField( TheFrame: ScrnTypes.DisplayFrame;
  338. FieldName: ARRAY OF CHAR; VAR TheList: GenLists.GenList );
  339. BEGIN
  340. IF 0 # ScrnUtl1.FieldNum( TheFrame, FieldName ) THEN
  341. IF ScrnUtl1.ListFromEdField( TheFrame,
  342. TheFrame^.CurrentField, TheList ) THEN
  343. RETURN;
  344. END;
  345. END;
  346. HALT();
  347. END GetEdField;
  348. BEGIN
  349. Initialized := FALSE;
  350. Init();
  351. END ScrnUtl2.