MSGBOX2.MOD 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. IMPLEMENTATION MODULE MsgBox2;
  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/msgbox2.mov 1.5 10 Mar 1991 15:29:52 coleb $
  12. *
  13. *)
  14. IMPORT ControlUtils;
  15. IMPORT DspFiles;
  16. IMPORT FramePainter;
  17. IMPORT FrameManager;
  18. IMPORT GenLists;
  19. IMPORT InputManager;
  20. IMPORT ListUtils;
  21. IMPORT M2Strings;
  22. IMPORT Numbers;
  23. IMPORT NumTypes;
  24. IMPORT PosUtils;
  25. IMPORT ScrnTypes;
  26. IMPORT ScrnUtl1;
  27. IMPORT ScrnUtl2;
  28. IMPORT SYSTEM;
  29. IMPORT VWindows;
  30. VAR
  31. Initialized : BOOLEAN;
  32. PROCEDURE Init();
  33. BEGIN
  34. IF Initialized THEN
  35. RETURN;
  36. ELSE
  37. Initialized := TRUE;
  38. END;
  39. ControlUtils.Init();
  40. DspFiles.Init();
  41. FramePainter.Init();
  42. FrameManager.Init();
  43. GenLists.Init();
  44. InputManager.Init();
  45. ListUtils.Init();
  46. M2Strings.Init();
  47. Numbers.Init();
  48. NumTypes.Init();
  49. PosUtils.Init();
  50. ScrnTypes.Init();
  51. ScrnUtl1.Init();
  52. ScrnUtl2.Init();
  53. VWindows.Init();
  54. END Init;
  55. PROCEDURE sub( n1, n2: CARDINAL ): CARDINAL;
  56. BEGIN
  57. IF n1 > n2 THEN
  58. RETURN n1 - n2;
  59. ELSE
  60. RETURN 0;
  61. END;
  62. END sub;
  63. CONST
  64. lftcol = 4;
  65. toprow = 3;
  66. rtcol = 42;
  67. btmrow = 14;
  68. midcol = 24;
  69. midrow = 9;
  70. (* These define starting points for msg box areas that we
  71. use if we can't put the box inside the current frame. *)
  72. PROCEDURE FindExteriorCoords( locatn: VWindows.Compass; ListWidth,
  73. ListHeight: CARDINAL; VAR col1, row1, col2, row2: CARDINAL );
  74. BEGIN
  75. CASE locatn OF
  76. VWindows.West, VWindows.NW, VWindows.SW :
  77. col1 := lftcol;
  78. | VWindows.North, VWindows.South :
  79. col1 := midcol;
  80. | VWindows.East, VWindows.NE, VWindows.SE :
  81. col1 := rtcol;
  82. END;
  83. CASE locatn OF
  84. VWindows.North, VWindows.NW, VWindows.NE :
  85. row1 := toprow;
  86. | VWindows.East, VWindows.West :
  87. row1 := midrow;
  88. | VWindows.South, VWindows.SE, VWindows.SW :
  89. row1 := btmrow;
  90. END;
  91. col2 := col1 + ListWidth + 3;
  92. row2 := row1 + ListHeight + 3;
  93. END FindExteriorCoords;
  94. PROCEDURE FindBestCoords( TheFrame: ScrnTypes.DisplayFrame;
  95. locatn: VWindows.Compass; ListWidth, ListHeight : CARDINAL;
  96. VAR col1, row1, col2, row2: CARDINAL );
  97. VAR
  98. width, height : CARDINAL;
  99. BEGIN
  100. width := TheFrame^.endcol - TheFrame^.startcol + 1;
  101. height := TheFrame^.endrow - TheFrame^.startrow + 1;
  102. CASE locatn OF
  103. VWindows.West, VWindows.NW, VWindows.SW :
  104. col1 := TheFrame^.startcol + 4;
  105. col2 := TheFrame^.startcol + (width DIV 2);
  106. | VWindows.East, VWindows.NE, VWindows.SE :
  107. col1 := sub( TheFrame^.endcol, width DIV 2 );
  108. col2 := sub( TheFrame^.endcol, 4 );
  109. ELSE
  110. col1 := TheFrame^.startcol + (width DIV 4);
  111. col2 := sub( TheFrame^.endcol, width DIV 4 );
  112. END;
  113. CASE locatn OF
  114. VWindows.North, VWindows.NW, VWindows.NE :
  115. row1 := TheFrame^.startrow + 4;
  116. row2 := TheFrame^.startrow + (height DIV 2);
  117. | VWindows.South, VWindows.SE, VWindows.SW :
  118. row1 := sub( TheFrame^.endrow, height DIV 2 );
  119. row2 := sub( TheFrame^.endrow, 4 );
  120. ELSE
  121. row1 := TheFrame^.startrow + (height DIV 4);
  122. row2 := sub( TheFrame^.endrow, height DIV 4 );
  123. END;
  124. IF (row1 >= row2) OR (col1 >= col2) THEN
  125. FindExteriorCoords( locatn, ListWidth, ListHeight,
  126. col1, row1, col2, row2 );
  127. END;
  128. END FindBestCoords;
  129. PROCEDURE LstMsgBox( TheFrame: ScrnTypes.DisplayFrame;
  130. locatn : VWindows.Compass; VAR TheList: GenLists.GenList );
  131. VAR
  132. MsgFrame: ScrnTypes.DisplayFrame;
  133. LinesAdded, BytesAdded : INTEGER;
  134. StartLine, CursorLine, CursorCol,
  135. col1, row1, col2, row2 : CARDINAL;
  136. BytePos: LONGINT;
  137. DummyName: ScrnTypes.AFrameName;
  138. BEGIN
  139. StartLine := 1;
  140. CursorLine := 1;
  141. CursorCol := 1;
  142. BytePos := NumTypes.L0;
  143. ListUtils.ReformPara( TheList, 0, 32, StartLine,
  144. CursorLine, CursorCol, LinesAdded, BytesAdded, BytePos );
  145. (* We're reformatting twice here -- first to help us find
  146. a good location for the window, and second to
  147. determine how large the window should be. *)
  148. FindBestCoords( TheFrame, locatn,
  149. ListUtils.LongestLine(TheList),
  150. GenLists.ListLength(TheList), col1, row1, col2,
  151. row2 );
  152. ScrnTypes.InitDisplayFrame( MsgFrame, TheFrame^.WindowHandle );
  153. StartLine := 1;
  154. CursorLine := 1;
  155. CursorCol := 1;
  156. BytePos := NumTypes.L0;
  157. ListUtils.ReformPara( TheList, 0, (col2 - col1) - 1, StartLine,
  158. CursorLine, CursorCol, LinesAdded, BytesAdded, BytePos );
  159. row2 := Numbers.Min( row2, row1 + GenLists.ListLength(TheList) + 1 );
  160. row2 := Numbers.Max( row2, row1 + 3 );
  161. (*Make sure we've got at least a two line window.*)
  162. MsgFrame^.startcol := col1;
  163. MsgFrame^.startrow := row1;
  164. MsgFrame^.endcol := col2;
  165. MsgFrame^.endrow := row2;
  166. MsgFrame^.action := 'I';
  167. MsgFrame^.normfor := TheFrame^.msgfor;
  168. MsgFrame^.normbak := TheFrame^.msgbak;
  169. MsgFrame^.normatrb := TheFrame^.msgatrb;
  170. ScrnUtl1.SetNormalColors( MsgFrame );
  171. ScrnUtl2.ListToFrame( TheList, MsgFrame );
  172. FramePainter.ShowDisplayFrame( MsgFrame, 0, 0, 0, 0 );
  173. InputManager.ControlFrame( MsgFrame, 1, '', FALSE, DummyName );
  174. FrameManager.EraseFrame( MsgFrame );
  175. ScrnUtl2.CloseDisplayFrame( MsgFrame );
  176. InputManager.LookAlive( TheFrame );
  177. END LstMsgBox;
  178. PROCEDURE StrMsgBox( TheFrame: ScrnTypes.DisplayFrame;
  179. locatn : VWindows.Compass; TheStr : ARRAY OF CHAR );
  180. VAR
  181. TmpList: GenLists.GenList;
  182. BEGIN
  183. GenLists.NewList( TmpList );
  184. GenLists.ListInsert( TheStr, GenLists.StrCode, TmpList, 1 );
  185. LstMsgBox( TheFrame, locatn, TmpList );
  186. GenLists.DisposeList( TmpList );
  187. END StrMsgBox;
  188. PROCEDURE LstMsgBoxExterior( TheFrame: ScrnTypes.DisplayFrame;
  189. locatn : VWindows.Compass; VAR TheList: GenLists.GenList );
  190. VAR
  191. MsgFrame: ScrnTypes.DisplayFrame;
  192. LinesAdded, BytesAdded : INTEGER;
  193. StartLine, CursorLine, CursorCol,
  194. col1, row1, col2, row2 : CARDINAL;
  195. BytePos: LONGINT;
  196. DummyName: ScrnTypes.AFrameName;
  197. BEGIN
  198. StartLine := 1;
  199. CursorLine := 1;
  200. CursorCol := 1;
  201. BytePos := NumTypes.L0;
  202. ListUtils.ReformPara( TheList, 0, 32, StartLine,
  203. CursorLine, CursorCol, LinesAdded, BytesAdded, BytePos );
  204. (* We're reformatting twice here -- first to help us find
  205. a good location for the window, and second to
  206. determine how large the window should be. *)
  207. StartLine := 1;
  208. (* Reset StartLine because it moves to end of paragraph
  209. in ReformPara above. *)
  210. FindExteriorCoords( locatn, ListUtils.LongestLine(TheList),
  211. GenLists.ListLength(TheList), col1, row1, col2, row2 );
  212. ScrnTypes.InitDisplayFrame( MsgFrame, TheFrame^.WindowHandle );
  213. StartLine := 1;
  214. CursorLine := 1;
  215. CursorCol := 1;
  216. BytePos := NumTypes.L0;
  217. ListUtils.ReformPara( TheList, 0, (col2 - col1) - 1, StartLine,
  218. CursorLine, CursorCol, LinesAdded, BytesAdded, BytePos );
  219. row2 := Numbers.Min( row2, row1 + GenLists.ListLength(TheList) + 1 );
  220. row2 := Numbers.Max( row2, row1 + 3 );
  221. (*Make sure we've got at least a two line window.*)
  222. MsgFrame^.startcol := col1;
  223. MsgFrame^.startrow := row1;
  224. MsgFrame^.endcol := col2;
  225. MsgFrame^.endrow := row2;
  226. MsgFrame^.action := 'I';
  227. MsgFrame^.normfor := TheFrame^.msgfor;
  228. MsgFrame^.normbak := TheFrame^.msgbak;
  229. MsgFrame^.normatrb := TheFrame^.msgatrb;
  230. ScrnUtl1.SetNormalColors( MsgFrame );
  231. ScrnUtl2.ListToFrame( TheList, MsgFrame );
  232. FramePainter.ShowDisplayFrame( MsgFrame, 0, 0, 0, 0 );
  233. InputManager.ControlFrame( MsgFrame, 1, '', FALSE, DummyName );
  234. FrameManager.EraseFrame( MsgFrame );
  235. ScrnUtl2.CloseDisplayFrame( MsgFrame );
  236. InputManager.LookAlive( TheFrame );
  237. END LstMsgBoxExterior;
  238. PROCEDURE StrMsgBoxExterior( TheFrame: ScrnTypes.DisplayFrame;
  239. locatn : VWindows.Compass; TheStr : ARRAY OF CHAR );
  240. VAR
  241. TmpList: GenLists.GenList;
  242. BEGIN
  243. GenLists.NewList( TmpList );
  244. GenLists.ListInsert( TheStr, GenLists.StrCode, TmpList, 1 );
  245. LstMsgBoxExterior( TheFrame, locatn, TmpList );
  246. GenLists.DisposeList( TmpList );
  247. END StrMsgBoxExterior;
  248. PROCEDURE MsgOkay( TheFrame: ScrnTypes.DisplayFrame;
  249. locatn : VWindows.Compass; TheStr : ARRAY OF CHAR ): BOOLEAN;
  250. VAR
  251. TmpList: GenLists.GenList;
  252. MsgFrame: ScrnTypes.DisplayFrame;
  253. LinesAdded, BytesAdded : INTEGER;
  254. StartLine, CursorLine, CursorCol,
  255. col1, row1, col2, row2, ListEnd : CARDINAL;
  256. BytePos: LONGINT;
  257. NextFrame: ScrnTypes.AFrameName;
  258. blank: CHAR;
  259. BEGIN
  260. blank := ' ';
  261. GenLists.NewList( TmpList );
  262. GenLists.ListInsert( TheStr, GenLists.StrCode, TmpList, 1 );
  263. ListUtils.InsertIntoElmt( TmpList, 1, SYSTEM.ADR(blank), 1, 0 );
  264. (* We insert a blank so that ReformPara will know to put
  265. a leading blank on each line; keeps message from crowding
  266. left edge of box. *)
  267. StartLine := 1;
  268. CursorLine := 1;
  269. CursorCol := 1;
  270. BytePos := NumTypes.L0;
  271. ListUtils.ReformPara( TmpList, 1, 32, StartLine,
  272. CursorLine, CursorCol, LinesAdded, BytesAdded, BytePos );
  273. (* We're reformatting twice here -- first to help us find
  274. a good location for the window, and second to
  275. determine how large the window should be. *)
  276. StartLine := 1;
  277. (* Reset StartLine because it moves to end of paragraph
  278. in ReformPara above. *)
  279. FindExteriorCoords( locatn, ListUtils.LongestLine(TmpList),
  280. GenLists.ListLength(TmpList), col1, row1, col2, row2 );
  281. ListUtils.ReformPara( TmpList, 1, (col2 - col1) - 1, StartLine,
  282. CursorLine, CursorCol, LinesAdded, BytesAdded, BytePos );
  283. ListEnd := GenLists.ListLength(TmpList);
  284. ScrnTypes.InitDisplayFrame( MsgFrame, TheFrame^.WindowHandle );
  285. row2 := Numbers.Min( row2, row1 + ListEnd + 3 );
  286. row2 := Numbers.Max( row2, row1 + 3 );
  287. (*Make sure we've got at least a two line window.*)
  288. MsgFrame^.startcol := col1;
  289. MsgFrame^.startrow := row1;
  290. MsgFrame^.endcol := col2;
  291. MsgFrame^.endrow := row2;
  292. MsgFrame^.action := 'I';
  293. MsgFrame^.EntryBox := VWindows.SingleBox;
  294. MsgFrame^.normfor := TheFrame^.msgfor;
  295. MsgFrame^.normbak := TheFrame^.msgbak;
  296. MsgFrame^.normatrb := TheFrame^.msgatrb;
  297. ScrnUtl1.SetNormalColors( MsgFrame );
  298. ScrnUtl2.ListToFrame( TmpList, MsgFrame );
  299. ControlUtils.AddMenuItem( MsgFrame, 4, ListEnd + 3,
  300. 'Okay', 4, ORD('O'), 'Okay' );
  301. ControlUtils.AddMenuItem( MsgFrame, 12, ListEnd + 3,
  302. 'Cancel', 6, ORD('C'), 'Cancel' );
  303. FramePainter.ShowDisplayFrame( MsgFrame, 0, 0, 0, 0 );
  304. InputManager.ControlFrame( MsgFrame, 1, '', FALSE, NextFrame );
  305. FrameManager.EraseFrame( MsgFrame );
  306. ScrnUtl2.CloseDisplayFrame( MsgFrame );
  307. InputManager.LookAlive( TheFrame );
  308. GenLists.DisposeList( TmpList );
  309. RETURN PosUtils.Equal( NextFrame, 'Okay' );
  310. END MsgOkay;
  311. BEGIN
  312. Initialized := FALSE;
  313. Init();
  314. END MsgBox2.